diff options
author | Xavier Ducrohet <xav@google.com> | 2013-12-04 02:40:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-12-04 02:40:02 +0000 |
commit | 863bbb6c5429fe7b80da4bbd340cc9512e9c79db (patch) | |
tree | 3ba24d466cba03b75e17ffb5064f204fdc61c9b3 | |
parent | c22036f5b99f23fa2ff8de5fb796602e7a636a2e (diff) | |
parent | ac055ae77a7b0c599727a38e18b872e294b15087 (diff) | |
download | build-863bbb6c5429fe7b80da4bbd340cc9512e9c79db.tar.gz |
Merge "Add option to filter resources."
11 files changed, 125 insertions, 57 deletions
diff --git a/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java b/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java index fef921d..2e5eb81 100644 --- a/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java +++ b/builder-model/src/main/java/com/android/builder/model/ProductFlavor.java @@ -19,6 +19,8 @@ package com.android.builder.model; import com.android.annotations.NonNull; import com.android.annotations.Nullable; +import java.util.Collection; + /** * a Product Flavor. This is only the configuration of the flavor. * @@ -144,4 +146,15 @@ public interface ProductFlavor extends BaseConfig { */ @Nullable NdkConfig getNdkConfig(); + + /** + * Returns the resource configuration for this variant. + * TODO implement this. + * + * This is the list of -c parameters for aapt. + * + * @return the resource configuration options. + */ + @NonNull + Collection<String> getResourceConfigurations(); } diff --git a/builder-model/src/main/java/com/android/builder/model/Variant.java b/builder-model/src/main/java/com/android/builder/model/Variant.java index 532901e..67813ae 100644 --- a/builder-model/src/main/java/com/android/builder/model/Variant.java +++ b/builder-model/src/main/java/com/android/builder/model/Variant.java @@ -86,15 +86,4 @@ public interface Variant { */ @NonNull ProductFlavor getMergedFlavor(); - - /** - * Returns the resource configuration for this variant. - * TODO implement this. - * - * This is the list of -c parameters for aapt. - * - * @return the resource configuration options. - */ - @NonNull - Collection<String> getResourceConfigurations(); } diff --git a/builder/src/main/java/com/android/builder/AndroidBuilder.java b/builder/src/main/java/com/android/builder/AndroidBuilder.java index ca577ed..0e12242 100644 --- a/builder/src/main/java/com/android/builder/AndroidBuilder.java +++ b/builder/src/main/java/com/android/builder/AndroidBuilder.java @@ -53,6 +53,7 @@ import com.android.sdklib.IAndroidTarget; import com.android.sdklib.repository.FullRevision; import com.android.utils.ILogger; import com.android.utils.SdkUtils; +import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -607,7 +608,8 @@ public class AndroidBuilder { @Nullable String proguardOutput, VariantConfiguration.Type type, boolean debuggable, - @NonNull AaptOptions options) + @NonNull AaptOptions options, + @NonNull Collection<String> resourceConfigs) throws IOException, InterruptedException, LoggedErrorException { checkNotNull(manifestFile, "manifestFile cannot be null."); @@ -706,6 +708,13 @@ public class AndroidBuilder { } } + if (!resourceConfigs.isEmpty()) { + command.add("-c"); + + Joiner joiner = Joiner.on(','); + command.add(joiner.join(resourceConfigs)); + } + if (symbolOutputDir != null && (type == VariantConfiguration.Type.LIBRARY || !libraries.isEmpty())) { command.add("--output-text-symbols"); diff --git a/builder/src/main/java/com/android/builder/DefaultProductFlavor.java b/builder/src/main/java/com/android/builder/DefaultProductFlavor.java index 7a7b757..2dbdd81 100644 --- a/builder/src/main/java/com/android/builder/DefaultProductFlavor.java +++ b/builder/src/main/java/com/android/builder/DefaultProductFlavor.java @@ -23,6 +23,11 @@ import com.android.builder.model.NdkConfig; import com.android.builder.model.ProductFlavor; import com.android.builder.model.SigningConfig; import com.google.common.base.Objects; +import com.google.common.collect.Sets; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Set; /** * The configuration of a product flavor. @@ -47,6 +52,7 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo private Boolean mTestHandleProfiling = null; private Boolean mTestFunctionalTest = null; private SigningConfig mSigningConfig = null; + private Set<String> mResourceConfiguration = null; /** * Creates a ProductFlavor with a given name. @@ -235,6 +241,40 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo return null; } + public void addResourceConfiguration(@NonNull String configuration) { + if (mResourceConfiguration == null) { + mResourceConfiguration = Sets.newHashSet(); + } + + mResourceConfiguration.add(configuration); + } + + public void addResourceConfigurations(@NonNull String... configurations) { + if (mResourceConfiguration == null) { + mResourceConfiguration = Sets.newHashSet(); + } + + mResourceConfiguration.addAll(Arrays.asList(configurations)); + } + + public void addResourceConfigurations(@NonNull Collection<String> configurations) { + if (mResourceConfiguration == null) { + mResourceConfiguration = Sets.newHashSet(); + } + + mResourceConfiguration.addAll(configurations); + } + + @NonNull + @Override + public Collection<String> getResourceConfigurations() { + if (mResourceConfiguration == null) { + mResourceConfiguration = Sets.newHashSet(); + } + + return mResourceConfiguration; + } + /** * Merges the flavor on top of a base platform and returns a new object with the result. * @param base the flavor to merge on top of @@ -271,6 +311,8 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo flavor.mSigningConfig = mSigningConfig != null ? mSigningConfig : base.mSigningConfig; + flavor.addResourceConfigurations(base.getResourceConfigurations()); + return flavor; } @@ -295,43 +337,30 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo DefaultProductFlavor that = (DefaultProductFlavor) o; - if (!mName.equals(that.mName)) return false; if (mMinSdkVersion != that.mMinSdkVersion) return false; - if (mTargetSdkVersion != that.mTargetSdkVersion) return false; if (mRenderscriptTargetApi != that.mRenderscriptTargetApi) return false; - if (mRenderscriptSupportMode != null ? - !mRenderscriptSupportMode.equals(that.mRenderscriptSupportMode) : - that.mRenderscriptSupportMode != null) + if (mTargetSdkVersion != that.mTargetSdkVersion) return false; + if (mVersionCode != that.mVersionCode) return false; + if (!mName.equals(that.mName)) return false; + if (mPackageName != null ? !mPackageName.equals(that.mPackageName) : that.mPackageName != null) return false; - if (mRenderscriptNdkMode != null ? - !mRenderscriptNdkMode.equals(that.mRenderscriptNdkMode) : - that.mRenderscriptNdkMode != null) + if (mRenderscriptNdkMode != null ? !mRenderscriptNdkMode.equals(that.mRenderscriptNdkMode) : that.mRenderscriptNdkMode != null) return false; - if (mVersionCode != that.mVersionCode) return false; - if (mPackageName != null ? - !mPackageName.equals(that.mPackageName) : - that.mPackageName != null) + if (mRenderscriptSupportMode != null ? !mRenderscriptSupportMode.equals(that.mRenderscriptSupportMode) : that.mRenderscriptSupportMode != null) + return false; + if (mResourceConfiguration != null ? !mResourceConfiguration.equals(that.mResourceConfiguration) : that.mResourceConfiguration != null) return false; - if (mTestInstrumentationRunner != null ? - !mTestInstrumentationRunner.equals(that.mTestInstrumentationRunner) : - that.mTestInstrumentationRunner != null) + if (mSigningConfig != null ? !mSigningConfig.equals(that.mSigningConfig) : that.mSigningConfig != null) return false; - if (mTestHandleProfiling != null ? - !mTestHandleProfiling.equals(that.mTestHandleProfiling) : - that.mTestHandleProfiling != null) + if (mTestFunctionalTest != null ? !mTestFunctionalTest.equals(that.mTestFunctionalTest) : that.mTestFunctionalTest != null) return false; - if (mTestFunctionalTest != null ? - !mTestFunctionalTest.equals(that.mTestFunctionalTest) : - that.mTestFunctionalTest != null) + if (mTestHandleProfiling != null ? !mTestHandleProfiling.equals(that.mTestHandleProfiling) : that.mTestHandleProfiling != null) return false; - if (mTestPackageName != null ? - !mTestPackageName.equals(that.mTestPackageName) : that.mTestPackageName != null) + if (mTestInstrumentationRunner != null ? !mTestInstrumentationRunner.equals(that.mTestInstrumentationRunner) : that.mTestInstrumentationRunner != null) return false; - if (mVersionName != null ? - !mVersionName.equals(that.mVersionName) : that.mVersionName != null) + if (mTestPackageName != null ? !mTestPackageName.equals(that.mTestPackageName) : that.mTestPackageName != null) return false; - if (mSigningConfig != null ? - !mSigningConfig.equals(that.mSigningConfig) : that.mSigningConfig != null) + if (mVersionName != null ? !mVersionName.equals(that.mVersionName) : that.mVersionName != null) return false; return true; @@ -350,13 +379,11 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo result = 31 * result + (mVersionName != null ? mVersionName.hashCode() : 0); result = 31 * result + (mPackageName != null ? mPackageName.hashCode() : 0); result = 31 * result + (mTestPackageName != null ? mTestPackageName.hashCode() : 0); - result = 31 * result + (mTestInstrumentationRunner != null ? - mTestInstrumentationRunner.hashCode() : 0); - result = 31 * result + (mTestHandleProfiling != null ? - mTestHandleProfiling.hashCode() : 0); - result = 31 * result + (mTestFunctionalTest != null ? - mTestFunctionalTest.hashCode() : 0); + result = 31 * result + (mTestInstrumentationRunner != null ? mTestInstrumentationRunner.hashCode() : 0); + result = 31 * result + (mTestHandleProfiling != null ? mTestHandleProfiling.hashCode() : 0); + result = 31 * result + (mTestFunctionalTest != null ? mTestFunctionalTest.hashCode() : 0); result = 31 * result + (mSigningConfig != null ? mSigningConfig.hashCode() : 0); + result = 31 * result + (mResourceConfiguration != null ? mResourceConfiguration.hashCode() : 0); return result; } @@ -378,11 +405,7 @@ public class DefaultProductFlavor extends BaseConfigImpl implements ProductFlavo .add("testHandleProfiling", mTestHandleProfiling) .add("testFunctionalTest", mTestFunctionalTest) .add("signingConfig", mSigningConfig) + .add("resConfig", mResourceConfiguration) .toString(); } - - /* - release signing info (keystore, key alias, passwords,...). - native abi filter - */ } diff --git a/changelog.txt b/changelog.txt index 77dfdba..792cac0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -19,6 +19,13 @@ PACKAGE_NAME, VERSION_CODE, VERSION_NAME, BUILD_TYPE, FLAVOR as well as FLAVOR_<group>, FLAVOR_<group>, etc... if there are several flavor dimensions. - Switch to ProGuard 4.10 - Added ability to test proguarded (obfuscated) apps. +- New option on product Flavor (and defaultConfig) allow filtering of resources through the -c option of aapt + You can pass single or multiple values through the DSL. All values from the default config and flavors + get combined and passed to aapt. + resConfig "en" + or + resConfig "nodpi","hdpi" + - Jar files are now pre-dexed for faster dexing. - First pass at NDK integration - API to add new generated source folders: diff --git a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy index 1e3605e..1e5fb45 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/BasePlugin.groovy @@ -678,6 +678,7 @@ public abstract class BasePlugin { processResources.conventionMapping.type = { variantConfiguration.type } processResources.conventionMapping.debuggable = { variantConfiguration.buildType.debuggable } processResources.conventionMapping.aaptOptions = { extension.aaptOptions } + processResources.conventionMapping.resourceConfigs = { variantConfiguration.mergedFlavor.resourceConfigurations } } protected void createProcessJavaResTask(BaseVariantData variantData) { diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/ProductFlavorDsl.groovy b/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/ProductFlavorDsl.groovy index cda61b0..669fc8f 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/ProductFlavorDsl.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/ProductFlavorDsl.groovy @@ -98,4 +98,15 @@ class ProductFlavorDsl extends DefaultProductFlavor { void ndk(Action<NdkConfigDsl> action) { action.execute(ndkConfig) } + + void resConfig(@NonNull String config) { + addResourceConfiguration(config); + } + + void resConfigs(@NonNull String... config) { + addResourceConfigurations(config); + } + void resConfigs(@NonNull Collection<String> config) { + addResourceConfigurations(config); + } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java index f00bd24..9f25e30 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/model/ProductFlavorImpl.java @@ -21,11 +21,14 @@ import com.android.annotations.Nullable; import com.android.builder.model.ClassField; import com.android.builder.model.NdkConfig; import com.android.builder.model.ProductFlavor; +import com.google.common.collect.Sets; import java.io.File; import java.io.Serializable; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Implementation of ProductFlavor that is serializable. Objects used in the DSL cannot be @@ -47,6 +50,7 @@ class ProductFlavorImpl implements ProductFlavor, Serializable { private String mTestInstrumentationRunner = null; private Boolean mTestHandleProfiling = null; private Boolean mTestFunctionalTest = null; + private Set<String> mResourceConfigurations = null; @NonNull static ProductFlavorImpl cloneFlavor(ProductFlavor productFlavor) { @@ -69,6 +73,9 @@ class ProductFlavorImpl implements ProductFlavor, Serializable { clonedFlavor.mTestHandleProfiling = productFlavor.getTestHandleProfiling(); clonedFlavor.mTestFunctionalTest = productFlavor.getTestFunctionalTest(); + clonedFlavor.mResourceConfigurations = Sets.newHashSet( + productFlavor.getResourceConfigurations()); + return clonedFlavor; } @@ -172,6 +179,12 @@ class ProductFlavorImpl implements ProductFlavor, Serializable { return null; } + @NonNull + @Override + public Collection<String> getResourceConfigurations() { + return mResourceConfigurations; + } + @Override public String toString() { return "ProductFlavorImpl{" + @@ -188,6 +201,7 @@ class ProductFlavorImpl implements ProductFlavor, Serializable { ", mTestInstrumentationRunner='" + mTestInstrumentationRunner + '\'' + ", mTestHandleProfiling='" + mTestHandleProfiling + '\'' + ", mTestFunctionalTest='" + mTestFunctionalTest + '\'' + + ", mResourceConfigurations='" + mResourceConfigurations + '\'' + '}'; } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/internal/model/VariantImpl.java b/gradle/src/main/groovy/com/android/build/gradle/internal/model/VariantImpl.java index c15f480..b8a04e6 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/internal/model/VariantImpl.java +++ b/gradle/src/main/groovy/com/android/build/gradle/internal/model/VariantImpl.java @@ -115,10 +115,4 @@ class VariantImpl implements Variant, Serializable { public Collection<JavaArtifact> getExtraJavaArtifacts() { return extraJavaArtifacts; } - - @Override - @NonNull - public List<String> getResourceConfigurations() { - return Collections.emptyList(); - } } diff --git a/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessAndroidResources.groovy b/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessAndroidResources.groovy index 201e47f..3c981ac 100644 --- a/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessAndroidResources.groovy +++ b/gradle/src/main/groovy/com/android/build/gradle/tasks/ProcessAndroidResources.groovy @@ -51,6 +51,9 @@ public class ProcessAndroidResources extends IncrementalTask { @OutputFile @Optional File proguardOutputFile + @Input + Collection<String> resourceConfigs + // ----- PRIVATE TASK API ----- @Nested @@ -88,6 +91,7 @@ public class ProcessAndroidResources extends IncrementalTask { getProguardOutputFile()?.absolutePath, getType(), getDebuggable(), - getAaptOptions()) + getAaptOptions(), + getResourceConfigs()) } } diff --git a/tests/basic/build.gradle b/tests/basic/build.gradle index b713714..b1c9749 100644 --- a/tests/basic/build.gradle +++ b/tests/basic/build.gradle @@ -45,6 +45,9 @@ android { buildConfigField "boolean", "DEFAULT", "true" buildConfigField "String", "FOO", "\"foo\"" + + resConfig "en" + resConfigs "nodpi", "hdpi" } buildTypes { |