diff options
author | Xavier Ducrohet <xav@android.com> | 2012-02-23 11:07:19 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-02-24 17:24:06 -0800 |
commit | 44a21c237072fba5454732c74d1f7653523c4105 (patch) | |
tree | fd5ea83ab6d2359acf969d231fe5b11a168aa7e1 /anttasks/src/com | |
parent | 9e36cb7689bf68ceafff3385e95dc24b756c34d5 (diff) | |
download | sdk-44a21c237072fba5454732c74d1f7653523c4105.zip sdk-44a21c237072fba5454732c74d1f7653523c4105.tar.gz sdk-44a21c237072fba5454732c74d1f7653523c4105.tar.bz2 |
Fix issue when a project and its libraries use the same jar files.
This is only an issue in Ant because in Eclipse we don't automatically
pull the jar files from libraries into the main project (we should somehow
now that we have the Library Projects jar container that is dynamic).
Right now we do a simple size/sha1 check on libraries that have the same
name to figure out if they are the same version. If they are we only
use one in the dex step (that notoriously fails to add the same class
twice). If they are different we stop the build as it's an error (having
two library projects depending on two different versions of a jar file
should be an error as we can be sure the two versions are API compatible).
For later: not use the file name only? find a way to version the libraries
and to have them declare whether they are API compatible with older versions?
Also added a hard-coded case for the Android Support Library. If both the v4
and the v13 are detected, use the v13 only as it includes the v4 already.
New test apps. Three cases:
- main and library projects with duplicate jar files that are identical
- main and library projects with duplicate jar files that are NOT identical
- main and library projects with v4 and v13 in the dependency list.
Change-Id: I3a9abdcbec635d7c9d3228bdd105120f77178b27
Diffstat (limited to 'anttasks/src/com')
-rw-r--r-- | anttasks/src/com/android/ant/DexExecTask.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java index 2d9479e..273f689 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.android.sdklib.build.JarListSanitizer; +import com.android.sdklib.build.JarListSanitizer.DifferentLibException; +import com.android.sdklib.build.JarListSanitizer.Sha1Exception; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.ExecTask; import org.apache.tools.ant.types.FileSet; @@ -162,8 +166,12 @@ public class DexExecTask extends SingleDependencyTask { task.createArg().setValue(mOutput); + paths = sanitizePaths(paths); + for (File f : paths) { - task.createArg().setValue(f.getAbsolutePath()); + String absPath = f.getAbsolutePath(); + System.out.println("Input: " + absPath); + task.createArg().setValue(absPath); } // execute it. @@ -177,4 +185,37 @@ public class DexExecTask extends SingleDependencyTask { protected String getExecTaskName() { return "dx"; } + + // private helper methods. + + private List<File> sanitizePaths(List<File> paths) { + // first get the non-files. + List<File> results = new ArrayList<File>(); + for (int i = 0 ; i < paths.size() ;) { + File f = paths.get(i); + // TEMP WORKAROUND: ignore classes.jar as all the output of libraries are + // called the same (in Ant) but are not actually the same jar file. + // TODO: Be aware of library output vs. regular jar dependency. + if (f.isFile() && f.getName().equals("classes.jar") == false) { + i++; + } else { + results.add(f); + paths.remove(i); + } + } + + File outputFile = new File(mOutput); + JarListSanitizer sanitizer = new JarListSanitizer(outputFile.getParentFile()); + + try { + results.addAll(sanitizer.sanitize(paths)); + } catch (DifferentLibException e) { + throw new BuildException(e.getMessage(), e); + } catch (Sha1Exception e) { + throw new BuildException( + "Failed to compute sha1 for " + e.getJarFile().getAbsolutePath(), e); + } + + return results; + } } |