From 98b631c6b3765be96b3707ba7aa54d52b10f4872 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 11 Jun 2012 17:05:22 -0700 Subject: Pre-dexed libraries. Change-Id: I5aabcf3d7acaa9573c991860db3fcc8ea34bc866 --- .../eclipse/adt/internal/build/BuildHelper.java | 53 +++++++++++++++++++++- .../ide/eclipse/adt/internal/build/DexWrapper.java | 3 +- 2 files changed, 53 insertions(+), 3 deletions(-) (limited to 'eclipse/plugins/com.android.ide.eclipse.adt') 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 finalInputPaths = new ArrayList(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 -- cgit v1.1