Specify --no-optimize to dx for APK debug builds.
Test Plan: Sandcastle builds.
diff --git a/src/com/facebook/buck/android/AndroidBinaryRule.java b/src/com/facebook/buck/android/AndroidBinaryRule.java
index ec26fb9..c2450b9 100644
--- a/src/com/facebook/buck/android/AndroidBinaryRule.java
+++ b/src/com/facebook/buck/android/AndroidBinaryRule.java
@@ -1082,7 +1082,8 @@
secondaryInputsDir,
successDir,
Optional.<Integer>absent(),
- dexSplitMode.getDexStore());
+ dexSplitMode.getDexStore(),
+ /* optimize */ PackageType.RELEASE.equals(packageType));
commands.add(smartDexingCommand);
}
diff --git a/src/com/facebook/buck/android/DxStep.java b/src/com/facebook/buck/android/DxStep.java
index 23866bf..de51a3d 100644
--- a/src/com/facebook/buck/android/DxStep.java
+++ b/src/com/facebook/buck/android/DxStep.java
@@ -32,15 +32,18 @@
private final String outputDexFile;
private final Set<Path> filesToDex;
+ private final boolean optimize;
/**
* @param outputDexFile path to the file where the generated classes.dex should go
* @param filesToDex each element in this set is a path to a .class file, a zip file of .class
* files, or a directory of .class files
+ * @param optimize If false, specify {@code --no-optimize}.
*/
- public DxStep(String outputDexFile, Iterable<Path> filesToDex) {
+ public DxStep(String outputDexFile, Iterable<Path> filesToDex, boolean optimize) {
this.outputDexFile = Preconditions.checkNotNull(outputDexFile);
this.filesToDex = ImmutableSet.copyOf(filesToDex);
+ this.optimize = optimize;
}
@Override
@@ -56,6 +59,10 @@
builder.add("--statistics");
}
+ if (!optimize) {
+ builder.add("--no-optimize");
+ }
+
// verbose flag, if appropriate.
if (context.getVerbosity().shouldUseVerbosityFlagIfAvailable()) {
builder.add("--verbose");
diff --git a/src/com/facebook/buck/android/SmartDexingStep.java b/src/com/facebook/buck/android/SmartDexingStep.java
index fc41a9d..7f389d5 100644
--- a/src/com/facebook/buck/android/SmartDexingStep.java
+++ b/src/com/facebook/buck/android/SmartDexingStep.java
@@ -72,6 +72,7 @@
private final Path successDir;
private final Optional<Integer> numThreads;
private final DexStore dexStore;
+ private final boolean optimizeDex;
private ListeningExecutorService dxExecutor;
/** Lazily initialized. See {@link InputResolver#createOutputToInputs(DexStore)}. */
@@ -99,7 +100,8 @@
Optional<String> secondaryInputsDir,
Path successDir,
Optional<Integer> numThreads,
- DexStore dexStore) {
+ DexStore dexStore,
+ boolean optimizeDex) {
this.inputResolver = new InputResolver(primaryOutputPath,
primaryInputsToDex,
secondaryOutputDir,
@@ -107,6 +109,7 @@
this.successDir = Preconditions.checkNotNull(successDir);
this.numThreads = Preconditions.checkNotNull(numThreads);
this.dexStore = Preconditions.checkNotNull(dexStore);
+ this.optimizeDex = optimizeDex;
}
@VisibleForTesting
@@ -241,7 +244,8 @@
}
})),
outputFile.getPath(),
- context.getProjectFilesystem().resolve(successDir.resolve(outputFile.getName()))));
+ context.getProjectFilesystem().resolve(successDir.resolve(outputFile.getName())),
+ optimizeDex));
}
ImmutableList.Builder<Step> commands = ImmutableList.builder();
@@ -340,16 +344,19 @@
private final Set<Path> srcs;
private final String outputPath;
private final Path outputHashPath;
+ private final boolean optimizeDex;
private String newInputsHash;
public DxPseudoRule(ExecutionContext context,
Set<Path> srcs,
String outputPath,
- Path outputHashPath) {
+ Path outputHashPath,
+ boolean optimizeDex) {
this.context = Preconditions.checkNotNull(context);
this.srcs = ImmutableSet.copyOf(srcs);
this.outputPath = Preconditions.checkNotNull(outputPath);
this.outputHashPath = Preconditions.checkNotNull(outputHashPath);
+ this.optimizeDex = optimizeDex;
}
/**
@@ -435,7 +442,7 @@
List<Step> steps = Lists.newArrayList();
if (useXzCompression()) {
String tempDexJarOutput = outputPath.replaceAll("\\.jar\\.xz$", ".tmp.jar");
- steps.add(new DxStep(tempDexJarOutput, srcs));
+ steps.add(new DxStep(tempDexJarOutput, srcs, optimizeDex));
// We need to make sure classes.dex is STOREd in the .dex.jar file, otherwise .XZ
// compression won't be effective.
String repackedJar = outputPath.replaceAll("\\.xz$", "");
@@ -448,7 +455,7 @@
steps.add(new RmStep(tempDexJarOutput, true));
steps.add(new XzStep(repackedJar));
} else {
- steps.add(new DxStep(outputPath, srcs));
+ steps.add(new DxStep(outputPath, srcs, optimizeDex));
}
steps.add(new WriteFileStep(newInputsHash, outputHashPath));
diff --git a/test/com/facebook/buck/android/SmartDexingStepTest.java b/test/com/facebook/buck/android/SmartDexingStepTest.java
index 02a13f6..a02d977 100644
--- a/test/com/facebook/buck/android/SmartDexingStepTest.java
+++ b/test/com/facebook/buck/android/SmartDexingStepTest.java
@@ -118,8 +118,11 @@
Path outputHashFile = new File(tmpDir.getRoot(), "out.dex.hash").toPath();
Files.write("dummy", outputHashFile.toFile(), Charsets.UTF_8);
- DxPseudoRule rule = new DxPseudoRule(context, ImmutableSet.of(testIn.toPath()),
- outputFile.getPath(), outputHashFile);
+ DxPseudoRule rule = new DxPseudoRule(context,
+ ImmutableSet.of(testIn.toPath()),
+ outputFile.getPath(),
+ outputHashFile,
+ /* optimizeDex */ false);
assertFalse("'dummy' is not a matching input hash", rule.checkIsCached());
// Write the real hash into the output hash file and ensure that checkIsCached now