aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2009-08-13 16:49:40 -0700
committerXavier Ducrohet <xav@android.com>2009-08-13 21:13:53 -0700
commit5f3b8ffcce0911c022c166822b0f08c90e1bb5c8 (patch)
treeda9d837ed2c0f01293a8fb28013c54baa4666e28 /anttasks/src
parente2783fe1e42f9cff6a2cff909ba6ea5f541e2e29 (diff)
downloadsdk-5f3b8ffcce0911c022c166822b0f08c90e1bb5c8.zip
sdk-5f3b8ffcce0911c022c166822b0f08c90e1bb5c8.tar.gz
sdk-5f3b8ffcce0911c022c166822b0f08c90e1bb5c8.tar.bz2
Make the Ant script sign and zipalign release builds.
It will also align debug builds. BUG: 2052744
Diffstat (limited to 'anttasks/src')
-rw-r--r--anttasks/src/com/android/ant/ApkBuilderTask.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java
index af87c78..3a15368 100644
--- a/anttasks/src/com/android/ant/ApkBuilderTask.java
+++ b/anttasks/src/com/android/ant/ApkBuilderTask.java
@@ -28,6 +28,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Path.PathElement;
import java.io.File;
import java.io.FileInputStream;
@@ -39,6 +40,9 @@ import java.util.Map.Entry;
public class ApkBuilderTask extends Task {
+ // ref id to the <path> object containing all the boot classpaths.
+ private final static String REF_APK_PATH = "android.apks.path";
+
/**
* Class to represent nested elements. Since they all have only one attribute ('path'), the
* same class can be used for all the nested elements (zip, file, sourcefolder, jarfolder,
@@ -152,7 +156,7 @@ public class ApkBuilderTask extends Task {
@Override
public void execute() throws BuildException {
- Project taskProject = getProject();
+ Project antProject = getProject();
ApkBuilderImpl apkBuilder = new ApkBuilderImpl();
apkBuilder.setVerbose(mVerbose);
@@ -197,13 +201,16 @@ public class ApkBuilderTask extends Task {
ApkBuilderImpl.processNativeFolder(offset, f, mNativeLibraries);
}
+ // create the Path item that will contain all the generated APKs
+ // for reuse by other targets (signing/zipaligning)
+ Path path = new Path(antProject);
// first do a full resource package
- createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/);
+ createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/, path);
// now see if we need to create file with filtered resources.
// Get the project base directory.
- File baseDir = taskProject.getBaseDir();
+ File baseDir = antProject.getBaseDir();
ProjectProperties properties = ProjectProperties.load(baseDir.getAbsolutePath(),
PropertyType.DEFAULT);
@@ -211,9 +218,13 @@ public class ApkBuilderTask extends Task {
if (apkConfigs.size() > 0) {
Set<Entry<String, String>> entrySet = apkConfigs.entrySet();
for (Entry<String, String> entry : entrySet) {
- createApk(apkBuilder, entry.getKey(), entry.getValue());
+ createApk(apkBuilder, entry.getKey(), entry.getValue(), path);
}
}
+
+ // finally sets the path in the project with a reference
+ antProject.addReference(REF_APK_PATH, path);
+
} catch (FileNotFoundException e) {
throw new BuildException(e);
} catch (IllegalArgumentException e) {
@@ -230,10 +241,12 @@ public class ApkBuilderTask extends Task {
* package will be generated.
* @param resourceFilter the resource configuration filter to pass to aapt (if configName is
* non null)
+ * @param path Ant {@link Path} to which add the generated APKs as {@link PathElement}
* @throws FileNotFoundException
* @throws ApkCreationException
*/
- private void createApk(ApkBuilderImpl apkBuilder, String configName, String resourceFilter)
+ private void createApk(ApkBuilderImpl apkBuilder, String configName, String resourceFilter,
+ Path path)
throws FileNotFoundException, ApkCreationException {
// All the files to be included in the archive have already been prep'ed up, except
// the resource package.
@@ -259,7 +272,7 @@ public class ApkBuilderTask extends Task {
}
if (mSigned) {
- filename = filename + "-debug.apk";
+ filename = filename + "-debug-unaligned.apk";
} else {
filename = filename + "-unsigned.apk";
}
@@ -284,8 +297,13 @@ public class ApkBuilderTask extends Task {
}
}
+ // out File
File f = new File(mOutFolder, filename);
+ // add it to the Path object
+ PathElement element = path.createPathElement();
+ element.setLocation(f);
+
// and generate the apk
apkBuilder.createPackage(f.getAbsoluteFile(), mZipArchives,
mArchiveFiles, mJavaResources, mResourcesJars, mNativeLibraries);