diff options
author | Googler <noreply@google.com> | 2016-08-09 17:09:18 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2016-08-10 08:37:25 +0000 |
commit | 2e6c76e27125a4326e25dd7375f9a1058d30da9d (patch) | |
tree | af6a70badc72691a181296b6792eaef4d2b3a1e6 /src/tools | |
parent | cf6021a7153f4e135bec2098af4dfa4291b5b398 (diff) |
Update DensitySpecificManifestProcessor to omit a <compatible-screens> declaration from the generated manifest if the list of requested densities contains an unsupported density.
Typically, the DensitySpecificManifestProcessor will add a <compatible-screens> declaration with a <screen> element for every density specified in the "densities=" argument of the android_binary build rule. If the "densities=" argument includes a density not officially supported by the Play Store, it will throw an exception and the build will fail.
After this change, an build rule that explicitly specifies a density not officially supported by the Play Store will instead result in the <compatible-screens> declaration being omitted from the generated manifest, indicating that the APK can support all densities.
--
MOS_MIGRATED_REVID=129761968
Diffstat (limited to 'src/tools')
2 files changed, 37 insertions, 11 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java index 4226a45bf7..13938dff32 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java @@ -48,7 +48,7 @@ public class DensitySpecificManifestProcessor { static final ImmutableList<String> SCREEN_SIZES = ImmutableList.of( "small", "normal", "large", "xlarge"); - static final ImmutableBiMap<String, String> SCREEN_DENSITIES = + static final ImmutableBiMap<String, String> PLAY_STORE_SUPPORTED_DENSITIES = ImmutableBiMap.<String, String>builder() .put("ldpi", "ldpi") .put("mdpi", "mdpi") @@ -124,7 +124,7 @@ public class DensitySpecificManifestProcessor { NodeList screenElements = doc.getElementsByTagName("screen"); for (int i = 0; i < screenElements.getLength(); i++) { Node screen = screenElements.item(i); - existingDensities.add(SCREEN_DENSITIES.inverse().get( + existingDensities.add(PLAY_STORE_SUPPORTED_DENSITIES.inverse().get( screen.getAttributes().getNamedItem("android:screenDensity").getNodeValue())); } if (existingDensities.containsAll(densities)) { @@ -137,15 +137,32 @@ public class DensitySpecificManifestProcessor { compatibleScreensElement.getParentNode().removeChild(compatibleScreensElement); } - Node compatibleScreens = doc.createElement("compatible-screens"); - manifestElement.appendChild(compatibleScreens); - + // If the list of densities provided in the android_binary build rule contains a density not + // supported by the Play Store, omit the <compatible-screens> declaration from the manifest to + // indicate that this APK supports all densities. This is a temporary fix to support new + // density buckets until the Play Store introduces a new density targeting mechanism. + boolean omitCompatibleScreens = false; for (String density : densities) { - for (String screenSize : SCREEN_SIZES) { - Element screen = doc.createElement("screen"); - screen.setAttribute("android:screenSize", screenSize); - screen.setAttribute("android:screenDensity", SCREEN_DENSITIES.get(density)); - compatibleScreens.appendChild(screen); + if (!PLAY_STORE_SUPPORTED_DENSITIES.containsKey(density)) { + omitCompatibleScreens = true; + System.out.println(density + " is not an accepted Play Store density."); + System.out.println("Omitting <compatible-screens> declaration from output manifest."); + break; + } + } + + if (!omitCompatibleScreens) { + Node compatibleScreens = doc.createElement("compatible-screens"); + manifestElement.appendChild(compatibleScreens); + + for (String density : densities) { + for (String screenSize : SCREEN_SIZES) { + Element screen = doc.createElement("screen"); + screen.setAttribute("android:screenSize", screenSize); + screen.setAttribute("android:screenDensity", + PLAY_STORE_SUPPORTED_DENSITIES.get(density)); + compatibleScreens.appendChild(screen); + } } } diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java index c5f7d45b44..e003a7df9d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.android; +import com.android.ide.common.res2.MergingException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -118,6 +119,7 @@ public class DensitySpecificResourceFilter { .put("hdpi", 240) .put("280dpi", 280) .put("xhdpi", 320) + .put("340dpi", 340) .put("400dpi", 400) .put("420dpi", 420) .put("xxhdpi", 480) @@ -154,10 +156,17 @@ public class DensitySpecificResourceFilter { * @param out The path to use for name spacing the final resource directory. * @param working The path of the working directory for the filtering */ - public DensitySpecificResourceFilter(List<String> densities, Path out, Path working) { + public DensitySpecificResourceFilter(List<String> densities, Path out, Path working) + throws MergingException { this.densities = densities; this.out = out; this.working = working; + + for (String density : densities) { + if (!DENSITY_MAP.containsKey(density)) { + throw new MergingException(density + " is not a known density qualifier."); + } + } } @VisibleForTesting |