aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar corysmith <corysmith@google.com>2017-06-26 17:10:40 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-26 18:43:08 +0200
commit5be05aa4c8f140391ef2196dd3762a908bd4cf93 (patch)
treee1b415b8c27b22826ab2faef7de7b30062707366 /src/main/java/com/google
parentc9ab594c1f9334fa20e70a9ec1bc0414c10d74a6 (diff)
Enabling Aapt2 processing:
* Add a new aapt_version attribute to android_binary * Add a new android_aapt_version flag to control the version of aapt used. * Add a new implicit output for aapt2 produced static libraries. * Add a new implicit output for aapt2 produced .flat files zip. RELNOTES: New property on android_sdk: aapt2 Choose the version of aapt on android_binary PiperOrigin-RevId: 160145530
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java51
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java76
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java5
4 files changed, 115 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
index 2580493643..40159bda72 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
@@ -107,6 +107,13 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
}
}
+ /** Converter for {@link AndroidAaptVersion} */
+ public static final class AndroidAaptConverter extends EnumConverter<AndroidAaptVersion> {
+ public AndroidAaptConverter() {
+ super(AndroidAaptVersion.class, "android androidAaptVersion");
+ }
+ }
+
/**
* Value used to avoid multiple configurations from conflicting.
*
@@ -191,6 +198,31 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
}
}
+ /** Types of android manifest mergers. */
+ public enum AndroidAaptVersion {
+ AAPT,
+ AAPT2,
+ AUTO;
+
+ public static List<String> getAttributeValues() {
+ return ImmutableList.of(
+ AAPT.name().toLowerCase(), AAPT2.name().toLowerCase(), getRuleAttributeDefault());
+ }
+
+ public static String getRuleAttributeDefault() {
+ return AUTO.name().toLowerCase();
+ }
+
+ public static AndroidAaptVersion fromString(String value) {
+ for (AndroidAaptVersion version : AndroidAaptVersion.values()) {
+ if (version.name().equalsIgnoreCase(value)) {
+ return version;
+ }
+ }
+ return null;
+ }
+ }
+
/** Android configuration options. */
public static class Options extends FragmentOptions {
@Option(
@@ -438,6 +470,18 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
)
public AndroidManifestMerger manifestMerger;
+ @Option(
+ name = "android_aapt",
+ defaultValue = "aapt",
+ category = "semantics",
+ optionUsageRestrictions = OptionUsageRestrictions.UNDOCUMENTED,
+ converter = AndroidAaptConverter.class,
+ help =
+ "Selects the version of androidAaptVersion to use for android_binary rules."
+ + "Flag to help the test and transition to aapt2."
+ )
+ public AndroidAaptVersion androidAaptVersion;
+
// Do not use on the command line.
@Option(
name = "experimental_use_parallel_android_resource_processing",
@@ -570,6 +614,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
host.dexoptsSupportedInIncrementalDexing = dexoptsSupportedInIncrementalDexing;
host.dexoptsSupportedInDexMerger = dexoptsSupportedInDexMerger;
host.manifestMerger = manifestMerger;
+ host.androidAaptVersion = androidAaptVersion;
return host;
}
@@ -630,6 +675,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
private final boolean includeLibraryResourceJars;
private final boolean useNocompressExtensionsOnApk;
private final boolean exportsManifestDefault;
+ private final AndroidAaptVersion androidAaptVersion;
private final boolean generateRobolectricRClass;
private final boolean useParallelDex2Oat;
@@ -664,6 +710,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
this.includeLibraryResourceJars = options.includeLibraryResourceJars;
this.useNocompressExtensionsOnApk = options.useNocompressExtensionsOnApk;
this.exportsManifestDefault = options.exportsManifestDefault;
+ this.androidAaptVersion = options.androidAaptVersion;
this.generateRobolectricRClass = options.generateRobolectricRClass;
this.useParallelDex2Oat = options.useParallelDex2Oat;
@@ -750,6 +797,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
return useParallelResourceProcessing;
}
+ public AndroidAaptVersion getAndroidAaptVersion() {
+ return androidAaptVersion;
+ }
+
public AndroidManifestMerger getManifestMerger() {
return manifestMerger;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
index 6dbe8a1e02..3fd71a9867 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
@@ -49,6 +49,7 @@ import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.packages.TriState;
+import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidAaptVersion;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration.AndroidManifestMerger;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration.ConfigurationDistinguisher;
import com.google.devtools.build.lib.rules.config.ConfigFeatureFlagProvider;
@@ -92,6 +93,12 @@ public final class AndroidRuleClasses {
fromTemplates("%{name}_resources.jar");
public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_APK =
fromTemplates("%{name}.ap_");
+ public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_AAPT2_LIBRARY_APK =
+ fromTemplates("%{name}_files/aapt2_library.ap_");
+ public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_AAPT2_R_TXT =
+ fromTemplates("%{name}_symbols/r.aapt2.txt");
+ public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_AAPT2_SOURCE_JAR =
+ fromTemplates("%{name}_files/%{name}_resources_aapt2-src.jar");
public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_SHRUNK_APK =
fromTemplates("%{name}_shrunk.ap_");
public static final SafeImplicitOutputsFunction ANDROID_RESOURCES_ZIP =
@@ -122,6 +129,8 @@ public final class AndroidRuleClasses {
fromTemplates("%{name}_symbols/local.bin");
public static final SafeImplicitOutputsFunction ANDROID_MERGED_SYMBOLS =
fromTemplates("%{name}_symbols/merged.bin");
+ public static final SafeImplicitOutputsFunction ANDROID_COMPILED_SYMBOLS =
+ fromTemplates("%{name}_symbols/symbols.zip");
public static final ImplicitOutputsFunction ANDROID_PROCESSED_MANIFEST =
fromTemplates("%{name}_processed_manifest/AndroidManifest.xml");
public static final SafeImplicitOutputsFunction MOBILE_INSTALL_STUB_APPLICATION_MANIFEST =
@@ -368,9 +377,14 @@ public final class AndroidRuleClasses {
// --proguard_top is not specified.
.add(attr("proguard", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
.add(attr("aapt", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
+ .add(attr("aapt2", LABEL).cfg(HOST).allowedFileTypes(ANY_FILE).exec())
.add(attr("dx", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
- .add(attr("main_dex_list_creator", LABEL)
- .mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
+ .add(
+ attr("main_dex_list_creator", LABEL)
+ .mandatory()
+ .cfg(HOST)
+ .allowedFileTypes(ANY_FILE)
+ .exec())
.add(attr("adb", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
.add(attr("framework_aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE))
.add(attr("aidl", LABEL).mandatory().cfg(HOST).allowedFileTypes(ANY_FILE).exec())
@@ -644,14 +658,14 @@ public final class AndroidRuleClasses {
.aspect(dexArchiveAspect, DexArchiveAspect.PARAM_EXTRACTOR))
.add(
attr("feature_of", LABEL)
- .allowedRuleClasses("android_binary")
- .allowedFileTypes()
- .undocumented("experimental, see b/36226333"))
+ .allowedRuleClasses("android_binary")
+ .allowedFileTypes()
+ .undocumented("experimental, see b/36226333"))
.add(
attr("feature_after", LABEL)
- .allowedRuleClasses("android_binary")
- .allowedFileTypes()
- .undocumented("experimental, see b/36226333"))
+ .allowedRuleClasses("android_binary")
+ .allowedFileTypes()
+ .undocumented("experimental, see b/36226333"))
.add(
attr("$build_incremental_dexmanifest", LABEL)
.cfg(HOST)
@@ -819,8 +833,10 @@ public final class AndroidRuleClasses {
.value(TriState.AUTO)
.undocumented("No-op, soon to be removed"))
.add(attr(":extra_proguard_specs", LABEL_LIST).value(JavaSemantics.EXTRA_PROGUARD_SPECS))
- .add(attr(":bytecode_optimizers", LABEL_LIST)
- .cfg(HOST).value(JavaSemantics.BYTECODE_OPTIMIZERS))
+ .add(
+ attr(":bytecode_optimizers", LABEL_LIST)
+ .cfg(HOST)
+ .value(JavaSemantics.BYTECODE_OPTIMIZERS))
.add(attr("rewrite_dexes_with_rex", BOOLEAN).value(false).undocumented("experimental"))
/*
File to be used as a package map for Rex tool that keeps the assignment of classes to
@@ -851,9 +867,10 @@ public final class AndroidRuleClasses {
--android_manifest_merger</a> flag.</li>
</ul>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("manifest_merger", STRING)
- .allowedValues(new AllowedValueSet(AndroidManifestMerger.getAttributeValues()))
- .value(AndroidManifestMerger.getRuleAttributeDefault()))
+ .add(
+ attr("manifest_merger", STRING)
+ .allowedValues(new AllowedValueSet(AndroidManifestMerger.getAttributeValues()))
+ .value(AndroidManifestMerger.getRuleAttributeDefault()))
/* <!-- #BLAZE_RULE(android_binary).ATTRIBUTE(manifest_values) -->
A dictionary of values to be overridden in the manifest. Any instance of ${name} in the
manifest will be replaced with the value corresponding to name in this dictionary.
@@ -864,12 +881,33 @@ public final class AndroidRuleClasses {
applicationId, versionCode and versionName will have any effect.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("manifest_values", STRING_DICT))
- .add(attr(AndroidFeatureFlagSetProvider.FEATURE_FLAG_ATTR, LABEL_KEYED_STRING_DICT)
- .undocumented("the feature flag feature has not yet been launched")
- .allowedRuleClasses("config_feature_flag")
- .allowedFileTypes()
- .nonconfigurable("defines an aspect of configuration")
- .mandatoryProviders(ImmutableList.of(ConfigFeatureFlagProvider.SKYLARK_IDENTIFIER)))
+ /* <!-- #BLAZE_RULE(android_binary).ATTRIBUTE(aapt_version) -->
+ Select the version of aapt for this rule.<br/>
+ Possible values:
+ <ul>
+ <li><code>aapt_version = "aapt"</code>: Use aapt. This is the current default
+ behaviour, and should be used for production binaries. The android_sdk rule must
+ have an aapt binary to use this option.</li>
+ <li><code>aapt_version = "aapt2"</code>: Use aapt2. This is the new resource
+ packaging system that provides improved incremental resource processing, smaller apks
+ and more. The android_sdk rule must have the aapt2 binary to use this option.</li>
+ <li><code>aapt_version = "auto"</code>: aapt is controlled by the
+ --android_aapt_version flag.</li>
+ </ul>
+ <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+ .add(
+ attr("aapt_version", STRING)
+ .undocumented("experimental, b/28819519")
+ .allowedValues(new AllowedValueSet(AndroidAaptVersion.getAttributeValues()))
+ .value(AndroidAaptVersion.getRuleAttributeDefault()))
+ .add(
+ attr(AndroidFeatureFlagSetProvider.FEATURE_FLAG_ATTR, LABEL_KEYED_STRING_DICT)
+ .undocumented("the feature flag feature has not yet been launched")
+ .allowedRuleClasses("config_feature_flag")
+ .allowedFileTypes()
+ .nonconfigurable("defines an aspect of configuration")
+ .mandatoryProviders(
+ ImmutableList.of(ConfigFeatureFlagProvider.SKYLARK_IDENTIFIER)))
.advertiseProvider(JavaCompilationArgsProvider.class)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
index 07b88a298b..164989c8a2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
@@ -46,6 +46,7 @@ public class AndroidSdk implements RuleConfiguredTargetFactory {
.get("build_tools_version", Type.STRING);
FilesToRunProvider aidl = ruleContext.getExecutablePrerequisite("aidl", Mode.HOST);
FilesToRunProvider aapt = ruleContext.getExecutablePrerequisite("aapt", Mode.HOST);
+ FilesToRunProvider aapt2 = ruleContext.getExecutablePrerequisite("aapt2", Mode.HOST);
FilesToRunProvider apkBuilder = ruleContext.getExecutablePrerequisite(
"apkbuilder", Mode.HOST);
FilesToRunProvider apkSigner = ruleContext.getExecutablePrerequisite("apksigner", Mode.HOST);
@@ -85,6 +86,7 @@ public class AndroidSdk implements RuleConfiguredTargetFactory {
mainDexListCreator,
aidl,
aapt,
+ aapt2,
apkBuilder,
apkSigner,
proguard,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java
index 4896bca245..30880f0e5d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java
@@ -41,6 +41,7 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider {
FilesToRunProvider mainDexListCreator,
FilesToRunProvider aidl,
FilesToRunProvider aapt,
+ @Nullable FilesToRunProvider aapt2,
@Nullable FilesToRunProvider apkBuilder,
FilesToRunProvider apkSigner,
FilesToRunProvider proguard,
@@ -60,6 +61,7 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider {
mainDexListCreator,
aidl,
aapt,
+ aapt2,
apkBuilder,
apkSigner,
proguard,
@@ -120,6 +122,9 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider {
public abstract FilesToRunProvider getAapt();
@Nullable
+ public abstract FilesToRunProvider getAapt2();
+
+ @Nullable
public abstract FilesToRunProvider getApkBuilder();
public abstract FilesToRunProvider getApkSigner();