Skip to content

Commit

Permalink
Add options to ResourceShrinkerAction to generate an updated R.txt.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=134312343
  • Loading branch information
apelle03 authored and katre committed Sep 27, 2016
1 parent 023a7bd commit f020e65
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,12 +138,27 @@ public static final class Options extends OptionsBase {
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;
Expand Down Expand Up @@ -216,6 +232,11 @@ public static void main(String[] args) throws Exception {
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,
Expand All @@ -230,7 +251,7 @@ public static void main(String[] args) throws Exception {
new MergedAndroidData(
shrunkResources, resourceFiles.resolve("assets"), options.primaryManifest),
ImmutableList.<DependencyAndroidData>of() /* libraries */,
null /* sourceOutputDir */,
generatedSources,
options.shrunkApk,
null /* proguardOutput */,
null /* mainDexProguardOutput */,
Expand All @@ -240,6 +261,12 @@ public static void main(String[] args) throws Exception {
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) {
Expand Down

0 comments on commit f020e65

Please sign in to comment.