From aa1abe879a53e1d25b8a95f677a920938097f3c9 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Tue, 25 Aug 2009 20:01:56 -0700 Subject: [PATCH] Make ApkBuilder create filenames supported by older rules. 'ant install' must know the debug apk filename so newer naming scheme breaks on older rule files (1.5 and earlier). The fix is to check for the presence of the property naming the debug, signed, unaligned package. If the property is present, then we use the new naming scheme ({base}[-{config}]-debug-unaligned.apk), else we use the old one ({base}-[-{config}]-debug.apk). Also merge the install/reinstall targets, since 'adb install -r ' works even if the apk was not yet installed. DO NOT MERGE --- .../src/com/android/ant/ApkBuilderTask.java | 28 ++++++++++++++++--- tools/scripts/android_rules.xml | 18 +++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/tools/anttasks/src/com/android/ant/ApkBuilderTask.java b/tools/anttasks/src/com/android/ant/ApkBuilderTask.java index 3a15368e0..9231dc9c2 100644 --- a/tools/anttasks/src/com/android/ant/ApkBuilderTask.java +++ b/tools/anttasks/src/com/android/ant/ApkBuilderTask.java @@ -205,8 +205,26 @@ public class ApkBuilderTask extends Task { // for reuse by other targets (signing/zipaligning) Path path = new Path(antProject); + // The createApk method uses mBaseName for the base name of the packages (resources + // and apk files). + // The generated apk file name is + // debug: {base}[-{config}]-debug-unaligned.apk + // release: {base}[-{config}]-unsigned.apk + // Unfortunately for 1.5 projects and before the 'install' ant target expects the name + // of the default debug package to be {base}-debug.apk + // In order to support those package, we look for the 'out-debug-unaligned-package' + // property. If this exist, then we generate {base}[-{config}]-debug-unaligned.apk + // otherwise we generate {base}[-{config}]-debug.apk + // FIXME: Make apkbuilder export the package name used instead of + // having to keep apkbuilder and the rules file in sync + String debugPackageSuffix = "-debug-unaligned.apk"; + if (antProject.getProperty("out-debug-unaligned-package") == null) { + debugPackageSuffix = "-debug.apk"; + } + // first do a full resource package - createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/, path); + createApk(apkBuilder, null /*configName*/, null /*resourceFilter*/, path, + debugPackageSuffix); // now see if we need to create file with filtered resources. // Get the project base directory. @@ -218,7 +236,8 @@ public class ApkBuilderTask extends Task { if (apkConfigs.size() > 0) { Set> entrySet = apkConfigs.entrySet(); for (Entry entry : entrySet) { - createApk(apkBuilder, entry.getKey(), entry.getValue(), path); + createApk(apkBuilder, entry.getKey(), entry.getValue(), path, + debugPackageSuffix); } } @@ -242,11 +261,12 @@ public class ApkBuilderTask extends Task { * @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} + * @param debugPackageSuffix suffix for the debug packages. * @throws FileNotFoundException * @throws ApkCreationException */ private void createApk(ApkBuilderImpl apkBuilder, String configName, String resourceFilter, - Path path) + Path path, String debugPackageSuffix) throws FileNotFoundException, ApkCreationException { // All the files to be included in the archive have already been prep'ed up, except // the resource package. @@ -272,7 +292,7 @@ public class ApkBuilderTask extends Task { } if (mSigned) { - filename = filename + "-debug-unaligned.apk"; + filename = filename + debugPackageSuffix; } else { filename = filename + "-unsigned.apk"; } diff --git a/tools/scripts/android_rules.xml b/tools/scripts/android_rules.xml index de44a7e6e..ad36cbe72 100644 --- a/tools/scripts/android_rules.xml +++ b/tools/scripts/android_rules.xml @@ -237,14 +237,6 @@ - Installing ${out-debug-package} onto default emulator... - - - - - - - Installing ${out-debug-package} onto default emulator... @@ -278,12 +270,10 @@ debug: Builds the application and sign it with a debug key. release: Builds the application. The generated apk file must be signed before it is published. - install: Installs the debug package onto a running emulator or - device. This can only be used if the application has - not yet been installed. - reinstall: Installs the debug package on a running emulator or - device that already has the application. - The signatures must match. + install: Installs/reinstall the debug package onto a running + emulator or device. + If the application was previously installed, the + signatures must match. uninstall: uninstall the application from a running emulator or device.