diff options
author | Xavier Ducrohet <xav@android.com> | 2012-03-07 16:45:10 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-03-07 17:06:54 -0800 |
commit | cc62a7f883c51fb8908bf936e894170d775385bc (patch) | |
tree | 491d05a5afbc9b6d946d6e36f626270c0445b6ff | |
parent | 2d4c066185bfb665b43aeab9c0fc4aa28d84613e (diff) | |
download | sdk-cc62a7f883c51fb8908bf936e894170d775385bc.tar.gz sdk-cc62a7f883c51fb8908bf936e894170d775385bc.tar.bz2 sdk-cc62a7f883c51fb8908bf936e894170d775385bc.zip |
Fix issue with proguard and resource files.
When using proguard, use the obfuscated jar file as source
of Java resources in case proguard renamed them.
(there are some options for that although I couldn't make them
work).
Change-Id: I63ed2c4f616a84180f03eb682691c02f0f28776c
3 files changed, 26 insertions, 29 deletions
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 ad4b7877f..e8fbadbb6 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 @@ -63,6 +63,7 @@ import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -111,6 +112,7 @@ public class BuildHelper { public static long sStartJavaCTime = 0; private final static int MILLION = 1000000; + private String mProguardFile; /** * An object able to put a marker on a resource. @@ -284,9 +286,7 @@ public class BuildHelper { * @param intermediateApk The path to the temporary resource file. * @param dex The path to the dex file. * @param output The path to the final package file to create. - * @param javaProject the java project being compiled * @param libProjects an optional list of library projects (can be null) - * @param referencedJavaProjects referenced projects. * @return true if success, false otherwise. * @throws ApkCreationException * @throws AndroidLocationException @@ -296,8 +296,7 @@ public class BuildHelper { * @throws DuplicateFileException */ public void finalDebugPackage(String intermediateApk, String dex, String output, - final IJavaProject javaProject, List<IProject> libProjects, - List<IJavaProject> referencedJavaProjects, ResourceMarker resMarker) + List<IProject> libProjects, ResourceMarker resMarker) throws ApkCreationException, KeytoolException, AndroidLocationException, NativeLibInJarException, DuplicateFileException, CoreException { @@ -321,8 +320,7 @@ public class BuildHelper { // from the keystore, get the signing info SigningInfo info = ApkBuilder.getDebugKey(keystoreOsPath, mVerbose ? mOutStream : null); - finalPackage(intermediateApk, dex, output, javaProject, libProjects, - referencedJavaProjects, + finalPackage(intermediateApk, dex, output, libProjects, info != null ? info.key : null, info != null ? info.certificate : null, resMarker); } @@ -338,9 +336,7 @@ public class BuildHelper { * @param dex The path to the dex file. * @param output The path to the final package file to create. * @param debugSign whether the apk must be signed with the debug key. - * @param javaProject the java project being compiled * @param libProjects an optional list of library projects (can be null) - * @param referencedJavaProjects referenced projects. * @param abiFilter an optional filter. If not null, then only the matching ABI is included in * the final archive * @return true if success, false otherwise. @@ -350,9 +346,8 @@ public class BuildHelper { * @throws DuplicateFileException */ public void finalPackage(String intermediateApk, String dex, String output, - final IJavaProject javaProject, List<IProject> libProjects, - List<IJavaProject> referencedJavaProjects, PrivateKey key, - X509Certificate certificate, ResourceMarker resMarker) + List<IProject> libProjects, + PrivateKey key, X509Certificate certificate, ResourceMarker resMarker) throws NativeLibInJarException, ApkCreationException, DuplicateFileException, CoreException { @@ -362,8 +357,16 @@ public class BuildHelper { mVerbose ? mOutStream: null); apkBuilder.setDebugMode(mDebugMode); + // either use the full compiled code paths or just the proguard file + // if present + Collection<String> pathsCollection = mCompiledCodePaths; + if (mProguardFile != null) { + pathsCollection = Collections.singletonList(mProguardFile); + mProguardFile = null; + } + // Now we write the standard resources from all the output paths. - for (String path : mCompiledCodePaths) { + for (String path : pathsCollection) { File file = new File(path); if (file.isFile()) { JarStatus jarStatus = apkBuilder.addResourcesFromJar(file); @@ -447,6 +450,10 @@ public class BuildHelper { } } + public void setProguardOutput(String proguardFile) { + mProguardFile = proguardFile; + } + public Collection<String> getCompiledCodePaths() { return mCompiledCodePaths; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java index 1c4f3f37a..8be6863ea 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java @@ -680,8 +680,7 @@ public class PostCompilerBuilder extends BaseBuilder { } helper.finalDebugPackage( osAndroidBinPath + File.separator + AdtConstants.FN_RESOURCES_AP_, - classesDexPath, osFinalPackagePath, - javaProject, libProjects, referencedJavaProjects, mResourceMarker); + classesDexPath, osFinalPackagePath, libProjects, mResourceMarker); } catch (KeytoolException e) { String eMessage = e.getMessage(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java index c95569be5..86c9b22a0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ExportHelper.java @@ -20,7 +20,6 @@ import static com.android.sdklib.internal.project.ProjectProperties.PROPERTY_SDK import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.AdtUtils; import com.android.ide.eclipse.adt.AndroidPrintStream; import com.android.ide.eclipse.adt.internal.build.BuildHelper; import com.android.ide.eclipse.adt.internal.build.DexException; @@ -237,6 +236,8 @@ public final class ExportHelper { helper.runProguard(proguardConfigFiles, inputJar, jars, obfuscatedJar, new File(project.getLocation().toFile(), SdkConstants.FD_PROGUARD)); + helper.setProguardOutput(obfuscatedJar.getAbsolutePath()); + // dx input is proguard's output dxInput = Collections.singletonList(obfuscatedJar.getAbsolutePath()); } else { @@ -246,9 +247,6 @@ public final class ExportHelper { } IJavaProject javaProject = JavaCore.create(project); - List<IProject> javaProjects = ProjectHelper.getReferencedProjects(project); - List<IJavaProject> referencedJavaProjects = BuildHelper.getJavaProjects( - javaProjects); helper.executeDx(javaProject, dxInput, dexFile.getAbsolutePath()); @@ -258,9 +256,7 @@ public final class ExportHelper { resourceFile.getAbsolutePath(), dexFile.getAbsolutePath(), outputFile.getAbsolutePath(), - javaProject, libProjects, - referencedJavaProjects, key, certificate, null); //resourceMarker @@ -375,17 +371,12 @@ public final class ExportHelper { private static void addFileToJar(JarOutputStream jar, File file, File rootDirectory) throws IOException { if (file.isDirectory()) { - for (File child: file.listFiles()) { - addFileToJar(jar, child, rootDirectory); + if (file.getName().equals("META-INF") == false) { + for (File child: file.listFiles()) { + addFileToJar(jar, child, rootDirectory); + } } - } else if (file.isFile()) { - // check the extension - String name = file.getName(); - if (!AdtUtils.endsWith(name, AdtConstants.DOT_CLASS)) { - return; - } - String rootPath = rootDirectory.getAbsolutePath(); String path = file.getAbsolutePath(); path = path.substring(rootPath.length()).replace("\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ |