diff options
3 files changed, 65 insertions, 4 deletions
diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java index f642c3d..9882fe9 100644 --- a/anttasks/src/com/android/ant/DexExecTask.java +++ b/anttasks/src/com/android/ant/DexExecTask.java @@ -16,6 +16,10 @@ package com.android.ant; +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.ExecTask; import org.apache.tools.ant.types.FileSet; @@ -121,19 +125,26 @@ public class DexExecTask extends SingleDependencyTask { 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 fileName = getDexFileName(input); + File dexedLib = new File(mDexedLibs, fileName); String dexedLibPath = dexedLib.getAbsolutePath(); if (dexedLib.isFile() == false || dexedLib.lastModified() < input.lastModified()) { - System.out.println("Pre-Dexing " + input); + System.out.println( + String.format("Pre-Dexing %1$s -> %2$s", + input.getAbsolutePath(), fileName)); if (dexedLib.isFile()) { dexedLib.delete(); } runDx(input, dexedLibPath, false /*showInput*/); + } else { + System.out.println( + String.format("Using Pre-Dexed %1$s <- %2$s", + fileName, input.getAbsolutePath())); } // replace the input with the pre-dex libs. @@ -142,6 +153,23 @@ public class DexExecTask extends SingleDependencyTask { } } + private String getDexFileName(File inputFile) { + // get the filename + String name = inputFile.getName(); + // remove the extension + int pos = name.lastIndexOf('.'); + if (pos != -1) { + name = name.substring(0, pos); + } + + // add a hash of the original file path + HashFunction hashFunction = Hashing.md5(); + HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath()); + + return name + "-" + hashCode.toString() + ".jar"; + } + + @Override public void execute() throws BuildException { 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 2ad8a09..b485a1a 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 @@ -40,6 +40,9 @@ import com.android.sdklib.internal.build.DebugKeyProvider.KeytoolException; import com.android.sdklib.util.GrabProcessOutput; import com.android.sdklib.util.GrabProcessOutput.IProcessOutput; import com.android.sdklib.util.GrabProcessOutput.Wait; +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -711,19 +714,24 @@ public class BuildHelper { // 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 fileName = getDexFileName(inputFile); + + File dexedLib = new File(dexedLibs, fileName); String dexedLibPath = dexedLib.getAbsolutePath(); if (dexedLib.isFile() == false || dexedLib.lastModified() < inputFile.lastModified()) { if (mVerbose) { - mOutStream.println("Pre-Dexing " + input); + mOutStream.println( + String.format("Pre-Dexing %1$s -> %2$s", input, fileName)); } if (dexedLib.isFile()) { @@ -738,6 +746,12 @@ public class BuildHelper { String message = String.format(Messages.Dalvik_Error_d, res); throw new DexException(message); } + } else { + if (mVerbose) { + mOutStream.println( + String.format("Using Pre-Dexed %1$s <- %2$s", + fileName, input)); + } } finalInputPaths.add(dexedLibPath); @@ -777,6 +791,22 @@ public class BuildHelper { } } + private String getDexFileName(File inputFile) { + // get the filename + String name = inputFile.getName(); + // remove the extension + int pos = name.lastIndexOf('.'); + if (pos != -1) { + name = name.substring(0, pos); + } + + // add a hash of the original file path + HashFunction hashFunction = Hashing.md5(); + HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath()); + + return name + "-" + hashCode.toString() + ".jar"; + } + /** * Executes aapt. If any error happen, files or the project will be marked. * @param command The command for aapt to execute. Currently supported: package and crunch diff --git a/eclipse/plugins/com.android.ide.eclipse.base/META-INF/MANIFEST.MF b/eclipse/plugins/com.android.ide.eclipse.base/META-INF/MANIFEST.MF index 5188818..cfa1d26 100644 --- a/eclipse/plugins/com.android.ide.eclipse.base/META-INF/MANIFEST.MF +++ b/eclipse/plugins/com.android.ide.eclipse.base/META-INF/MANIFEST.MF @@ -61,9 +61,12 @@ Export-Package: com.android, com.google.common.cache, com.google.common.collect, com.google.common.eventbus, + com.google.common.hash, com.google.common.io, + com.google.common.math, com.google.common.net, com.google.common.primitives, + com.google.common.reflect, com.google.common.util.concurrent, org.apache.commons.codec, org.apache.commons.codec.binary, |