Add options to ResourceShrinkerAction to generate an updated R.txt.
--
MOS_MIGRATED_REVID=134312343
diff --git a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java
index a4b5f6b..4b52715 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ResourceShrinkerAction.java
@@ -21,6 +21,7 @@
import com.google.devtools.build.android.Converters.ExistingPathConverter;
import com.google.devtools.build.android.Converters.PathConverter;
import com.google.devtools.build.android.Converters.PathListConverter;
+import com.google.devtools.build.android.Converters.VariantConfigurationTypeConverter;
import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
@@ -137,12 +138,27 @@
help = "Path to where the shrunk resource.ap_ should be written.")
public Path shrunkResources;
+ @Option(name = "rTxtOutput",
+ defaultValue = "null",
+ converter = PathConverter.class,
+ category = "output",
+ help = "Path to where the R.txt should be written.")
+ public Path rTxtOutput;
+
@Option(name = "log",
defaultValue = "null",
category = "output",
converter = PathConverter.class,
help = "Path to where the shrinker log should be written.")
public Path log;
+
+ @Option(name = "packageType",
+ defaultValue = "DEFAULT",
+ converter = VariantConfigurationTypeConverter.class,
+ category = "config",
+ help = "Variant configuration type for packaging the resources."
+ + " Acceptible values DEFAULT, LIBRARY, TEST")
+ public VariantConfiguration.Type packageType;
}
private static AaptConfigOptions aaptConfigOptions;
@@ -216,6 +232,11 @@
logger.fine(String.format("Shrinking resources finished at %sms",
timer.elapsed(TimeUnit.MILLISECONDS)));
+ Path generatedSources = null;
+ if (options.rTxtOutput != null) {
+ generatedSources = working.resolve("generated_resources");
+ }
+
// Build ap_ with shrunk resources.
resourceProcessor.processResources(
aaptConfigOptions.aapt,
@@ -230,7 +251,7 @@
new MergedAndroidData(
shrunkResources, resourceFiles.resolve("assets"), options.primaryManifest),
ImmutableList.<DependencyAndroidData>of() /* libraries */,
- null /* sourceOutputDir */,
+ generatedSources,
options.shrunkApk,
null /* proguardOutput */,
null /* mainDexProguardOutput */,
@@ -240,6 +261,12 @@
resourceProcessor.createResourcesZip(shrunkResources, resourceFiles.resolve("assets"),
options.shrunkResources, false /* compress */);
}
+ if (options.rTxtOutput != null) {
+ resourceProcessor.copyRToOutput(
+ generatedSources,
+ options.rTxtOutput,
+ options.packageType == VariantConfiguration.Type.LIBRARY);
+ }
logger.fine(String.format("Packing resources finished at %sms",
timer.elapsed(TimeUnit.MILLISECONDS)));
} catch (Exception e) {