diff options
author | Xavier Ducrohet <xav@android.com> | 2012-06-11 17:05:22 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-09-21 13:19:15 -0700 |
commit | 98b631c6b3765be96b3707ba7aa54d52b10f4872 (patch) | |
tree | c446b2b16f8b359772127d867c6a24282db3bbc9 /anttasks/src | |
parent | 1d96433fc413046aeecc8bd9388fecad511ecefb (diff) | |
download | sdk-98b631c6b3765be96b3707ba7aa54d52b10f4872.zip sdk-98b631c6b3765be96b3707ba7aa54d52b10f4872.tar.gz sdk-98b631c6b3765be96b3707ba7aa54d52b10f4872.tar.bz2 |
Pre-dexed libraries.
Change-Id: I5aabcf3d7acaa9573c991860db3fcc8ea34bc866
Diffstat (limited to 'anttasks/src')
-rw-r--r-- | anttasks/src/com/android/ant/DexExecTask.java | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java index a2b2b07..f642c3d 100644 --- a/anttasks/src/com/android/ant/DexExecTask.java +++ b/anttasks/src/com/android/ant/DexExecTask.java @@ -24,6 +24,8 @@ import org.apache.tools.ant.types.resources.FileResource; import java.io.File; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -34,6 +36,7 @@ public class DexExecTask extends SingleDependencyTask { private String mExecutable; private String mOutput; + private String mDexedLibs; private boolean mVerbose = false; private boolean mNoLocals = false; private List<Path> mPathInputs; @@ -64,6 +67,10 @@ public class DexExecTask extends SingleDependencyTask { mOutput = TaskHelper.checkSinglePath("output", output); } + public void setDexedLibs(Path dexedLibs) { + mDexedLibs = TaskHelper.checkSinglePath("dexedLibs", dexedLibs); + } + /** * Sets the value of the "nolocals" attribute. * @param verbose the value. @@ -102,6 +109,39 @@ public class DexExecTask extends SingleDependencyTask { } + private void preDexLibraries(List<File> inputs) { + if (inputs.size() == 1) { + // only one input, no need to put a pre-dexed version, even if this path is + // just a jar file (case for proguard'ed builds) + return; + } + + final int count = inputs.size(); + for (int i = 0 ; i < count; i++) { + File input = inputs.get(i); + if (input.isFile()) { + // check if this libs needs to be pre-dexed + File dexedLib = new File(mDexedLibs, input.getName()); + String dexedLibPath = dexedLib.getAbsolutePath(); + + if (dexedLib.isFile() == false || + dexedLib.lastModified() < input.lastModified()) { + + System.out.println("Pre-Dexing " + input); + + if (dexedLib.isFile()) { + dexedLib.delete(); + } + + runDx(input, dexedLibPath, false /*showInput*/); + } + + // replace the input with the pre-dex libs. + inputs.set(i, dexedLib); + } + } + } + @Override public void execute() throws BuildException { @@ -110,6 +150,7 @@ public class DexExecTask extends SingleDependencyTask { if (mPathInputs != null) { for (Path pathList : mPathInputs) { for (String path : pathList.list()) { + System.out.println("input: " + path); paths.add(new File(path)); } } @@ -120,11 +161,15 @@ public class DexExecTask extends SingleDependencyTask { Iterator<?> iter = fs.iterator(); while (iter.hasNext()) { FileResource fr = (FileResource) iter.next(); + System.out.println("input: " + fr.getFile().toString()); paths.add(fr.getFile()); } } } + // pre dex libraries if needed + preDexLibraries(paths); + // figure out the path to the dependency file. String depFile = mOutput + ".d"; @@ -141,6 +186,17 @@ public class DexExecTask extends SingleDependencyTask { System.out.println(String.format( "Converting compiled files and external libraries into %1$s...", mOutput)); + runDx(paths, mOutput, mVerbose /*showInputs*/); + + // generate the dependency file. + generateDependencyFile(depFile, inputPaths, mOutput); + } + + private void runDx(File input, String output, boolean showInputs) { + runDx(Collections.singleton(input), output, showInputs); + } + + private void runDx(Collection<File> inputs, String output, boolean showInputs) { ExecTask task = new ExecTask(); task.setProject(getProject()); task.setOwningTarget(getOwningTarget()); @@ -159,11 +215,11 @@ public class DexExecTask extends SingleDependencyTask { } task.createArg().setValue("--output"); - task.createArg().setValue(mOutput); + task.createArg().setValue(output); - for (File f : paths) { - String absPath = f.getAbsolutePath(); - if (mVerbose) { + for (File input : inputs) { + String absPath = input.getAbsolutePath(); + if (showInputs) { System.out.println("Input: " + absPath); } task.createArg().setValue(absPath); @@ -171,9 +227,6 @@ public class DexExecTask extends SingleDependencyTask { // execute it. task.execute(); - - // generate the dependency file. - generateDependencyFile(depFile, inputPaths, mOutput); } @Override |