diff options
author | Xavier Ducrohet <xav@android.com> | 2012-09-21 14:02:10 -0700 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-09-21 14:02:11 -0700 |
commit | 225fe918975d7a87daebd5f37afa60a46075699d (patch) | |
tree | e70d051babd4092a42c73285bed9c68078fc473d | |
parent | 944abd952560b2a40474cabad2d2ad786172164b (diff) | |
parent | 98b631c6b3765be96b3707ba7aa54d52b10f4872 (diff) | |
download | sdk-225fe918975d7a87daebd5f37afa60a46075699d.zip sdk-225fe918975d7a87daebd5f37afa60a46075699d.tar.gz sdk-225fe918975d7a87daebd5f37afa60a46075699d.tar.bz2 |
Merge "Pre-dexed libraries."
4 files changed, 116 insertions, 10 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 diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java index f3a3d57..5fb6660 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java @@ -23,6 +23,7 @@ import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AndroidPrintStream; import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs; import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs.BuildVerbosity; +import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.IAndroidTarget; @@ -694,14 +695,62 @@ public class BuildHelper { mOutStream.setPrefix(CONSOLE_PREFIX_DX); mErrStream.setPrefix(CONSOLE_PREFIX_DX); - if (mVerbose) { + IFolder binFolder = BaseProjectHelper.getAndroidOutputFolder(javaProject.getProject()); + File binFile = binFolder.getLocation().toFile(); + File dexedLibs = new File(binFile, "dexedLibs"); + if (dexedLibs.exists() == false) { + dexedLibs.mkdir(); + } + + // replace the libs by their dexed versions (dexing them if needed.) + List<String> finalInputPaths = new ArrayList<String>(inputPaths.size()); + if (inputPaths.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) + finalInputPaths.addAll(inputPaths); + } else { for (String input : inputPaths) { + File inputFile = new File(input); + if (inputFile.isDirectory()) { + finalInputPaths.add(input); + } else if (inputFile.isFile()) { + File dexedLib = new File(dexedLibs, inputFile.getName()); + String dexedLibPath = dexedLib.getAbsolutePath(); + + if (dexedLib.isFile() == false || + dexedLib.lastModified() < inputFile.lastModified()) { + + if (mVerbose) { + mOutStream.println("Pre-Dexing " + input); + } + + if (dexedLib.isFile()) { + dexedLib.delete(); + } + + int res = wrapper.run(dexedLibPath, Collections.singleton(input), + mVerbose, mOutStream, mErrStream); + + if (res != 0) { + // output error message and mark the project. + String message = String.format(Messages.Dalvik_Error_d, res); + throw new DexException(message); + } + } + + finalInputPaths.add(dexedLibPath); + } + } + } + + if (mVerbose) { + for (String input : finalInputPaths) { mOutStream.println("Input: " + input); } } int res = wrapper.run(osOutFilePath, - inputPaths, + finalInputPaths, mVerbose, mOutStream, mErrStream); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/DexWrapper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/DexWrapper.java index 015d230..d786c04 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/DexWrapper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/DexWrapper.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.build; +import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; import org.eclipse.core.runtime.CoreException; @@ -173,7 +174,7 @@ public final class DexWrapper { Object args = mArgConstructor.newInstance(); mArgOutName.set(args, osOutFilePath); mArgFileNames.set(args, osFilenames.toArray(new String[osFilenames.size()])); - mArgJarOutput.set(args, false); + mArgJarOutput.set(args, osOutFilePath.endsWith(AdtConstants.DOT_JAR)); mArgVerbose.set(args, verbose); // call the run method diff --git a/files/ant/build.xml b/files/ant/build.xml index 4861c1d..9210c66 100644 --- a/files/ant/build.xml +++ b/files/ant/build.xml @@ -136,6 +136,7 @@ <property name="out.classes.absolute.dir" location="${out.dir}/classes" /> <property name="out.res.absolute.dir" location="${out.dir}/res" /> <property name="out.aidl.absolute.dir" location="${out.dir}/aidl" /> + <property name="out.dexed.absolute.dir" location="${out.dir}/dexedLibs" /> <property name="out.manifest.abs.file" location="${out.dir}/AndroidManifest.xml" /> <!-- tools location --> @@ -274,6 +275,7 @@ <dex executable="${dx}" output="${intermediate.dex.file}" + dexedlibs="${out.dexed.absolute.dir}" nolocals="@{nolocals}" verbose="${verbose}"> <path path="${out.dex.input.absolute.dir}"/> @@ -541,6 +543,7 @@ <do-only-if-manifest-hasCode> <mkdir dir="${gen.absolute.dir}" /> <mkdir dir="${out.classes.absolute.dir}" /> + <mkdir dir="${out.dexed.absolute.dir}" /> </do-only-if-manifest-hasCode> <echo level="info">----------</echo> |