aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-04-27 17:05:04 -0700
committerXavier Ducrohet <xav@android.com>2010-04-27 17:21:30 -0700
commitb2e132cffd83c46aa836d0b06ca2c66de87fff2e (patch)
treeb8cdc8b3f0f41d7ae9fed692d83ea10fc6a7ae2f
parent0fd2efc6912586032d5dbe6d5c63e242cf65a31a (diff)
downloadsdk-b2e132cffd83c46aa836d0b06ca2c66de87fff2e.zip
sdk-b2e132cffd83c46aa836d0b06ca2c66de87fff2e.tar.gz
sdk-b2e132cffd83c46aa836d0b06ca2c66de87fff2e.tar.bz2
Add ABI filtering and version code injection in the Ant rules and tasks.
Change-Id: Ic8e41c1ad5343b32d2766427ba271a79c88b3b66
-rw-r--r--anttasks/src/com/android/ant/AaptExecLoopTask.java17
-rw-r--r--anttasks/src/com/android/ant/ApkBuilderTask.java18
-rw-r--r--apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderImpl.java24
-rw-r--r--files/ant_rules_r3.xml8
4 files changed, 64 insertions, 3 deletions
diff --git a/anttasks/src/com/android/ant/AaptExecLoopTask.java b/anttasks/src/com/android/ant/AaptExecLoopTask.java
index 9fe2170..09354c0 100644
--- a/anttasks/src/com/android/ant/AaptExecLoopTask.java
+++ b/anttasks/src/com/android/ant/AaptExecLoopTask.java
@@ -79,6 +79,7 @@ public final class AaptExecLoopTask extends Task {
private String mCommand;
private boolean mForce = true; // true due to legacy reasons
private boolean mVerbose = false;
+ private int mVersionCode = 0;
private String mManifest;
private ArrayList<Path> mResources;
private String mAssets;
@@ -120,6 +121,17 @@ public final class AaptExecLoopTask extends Task {
mVerbose = verbose;
}
+ public void setVersioncode(String versionCode) {
+ if (versionCode.length() > 0) {
+ try {
+ mVersionCode = Integer.decode(versionCode);
+ } catch (NumberFormatException e) {
+ System.out.println(String.format(
+ "WARNING: Ignoring invalid version code value '%s'.", versionCode));
+ }
+ }
+ }
+
/**
* Sets the value of the "manifest" attribute.
* @param manifest the value.
@@ -356,6 +368,11 @@ public final class AaptExecLoopTask extends Task {
task.createArg().setValue("--auto-add-overlay");
}
+ if (mVersionCode != 0) {
+ task.createArg().setValue("--version-code");
+ task.createArg().setValue(Integer.toString(mVersionCode));
+ }
+
// manifest location
if (mManifest != null) {
task.createArg().setValue("-M");
diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java
index 3fdf4d5..9067ec7 100644
--- a/anttasks/src/com/android/ant/ApkBuilderTask.java
+++ b/anttasks/src/com/android/ant/ApkBuilderTask.java
@@ -46,6 +46,7 @@ public class ApkBuilderTask extends Task {
private boolean mVerbose = false;
private boolean mSigned = true;
private boolean mDebug = false;
+ private String mAbiFilter = null;
private final ArrayList<Path> mZipList = new ArrayList<Path>();
private final ArrayList<Path> mFileList = new ArrayList<Path>();
@@ -101,6 +102,21 @@ public class ApkBuilderTask extends Task {
}
/**
+ * Sets an ABI filter. If non <code>null</code>, then only native libraries matching the given
+ * ABI will be packaged with the APK.
+ * @param abiFilter the ABI to accept (and reject all other). If null or empty string, no ABIs
+ * are rejected. This must be a single ABI name as defined by the Android NDK. For a list
+ * of valid ABI names, see $NDK/docs/CPU-ARCH-ABIS.TXT
+ */
+ public void setAbifilter(String abiFilter) {
+ if (abiFilter != null && abiFilter.length() > 0) {
+ mAbiFilter = abiFilter.trim();
+ } else {
+ mAbiFilter = null;
+ }
+ }
+
+ /**
* Returns an object representing a nested <var>zip</var> element.
*/
public Object createZip() {
@@ -208,7 +224,7 @@ public class ApkBuilderTask extends Task {
for (Path pathList : mNativeList) {
for (String path : pathList.list()) {
ApkBuilderImpl.processNativeFolder(new File(path), mDebug,
- mNativeLibraries);
+ mNativeLibraries, mVerbose, mAbiFilter);
}
}
diff --git a/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderImpl.java b/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderImpl.java
index d8e0123..3189c41 100644
--- a/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderImpl.java
+++ b/apkbuilder/src/com/android/apkbuilder/internal/ApkBuilderImpl.java
@@ -148,7 +148,8 @@ public final class ApkBuilderImpl {
throw new WrongOptionException("Missing value for -nf");
}
- processNativeFolder(new File(args[index++]), mDebugMode, nativeLibraries);
+ processNativeFolder(new File(args[index++]), mDebugMode, nativeLibraries,
+ mVerbose, null /*abiFilter*/);
} else if ("-storetype".equals(argument)) {
// quick check on the next argument.
if (index == args.length) {
@@ -317,19 +318,38 @@ public final class ApkBuilderImpl {
* <p/>The root folder must include folders that include .so files.
* @param root the native root folder.
* @param nativeLibraries the collection to add native libraries to.
+ * @param verbose verbose mode.
+ * @param abiFilter optional ABI filter. If non-null only the given ABI is included.
* @throws ApkCreationException
*/
public static void processNativeFolder(File root, boolean debugMode,
- Collection<ApkFile> nativeLibraries) throws ApkCreationException {
+ Collection<ApkFile> nativeLibraries, boolean verbose, String abiFilter)
+ throws ApkCreationException {
if (root.isDirectory() == false) {
throw new ApkCreationException(root.getAbsolutePath() + " is not a folder!");
}
File[] abiList = root.listFiles();
+ if (verbose) {
+ System.out.println("Processing native folder: " + root.getAbsolutePath());
+ if (abiFilter != null) {
+ System.out.println("ABI Filter: " + abiFilter);
+ }
+ }
+
if (abiList != null) {
for (File abi : abiList) {
if (abi.isDirectory()) { // ignore files
+
+ // check the abi filter and reject all other ABIs
+ if (abiFilter != null && abiFilter.equals(abi.getName()) == false) {
+ if (verbose) {
+ System.out.println("Rejecting ABI " + abi.getName());
+ }
+ continue;
+ }
+
File[] libs = abi.listFiles();
if (libs != null) {
for (File lib : libs) {
diff --git a/files/ant_rules_r3.xml b/files/ant_rules_r3.xml
index ffd7c41..82abb6d 100644
--- a/files/ant_rules_r3.xml
+++ b/files/ant_rules_r3.xml
@@ -81,6 +81,12 @@
<property name="out.release.package"
location="${out.absolute.dir}/${ant.project.name}-release.apk" />
+ <!-- set some property used for filtering/override. If those weren't defined
+ before, then this will create them with empty values, which are then ignored
+ by the custom tasks receiving them. -->
+ <property name="version.code" value="" />
+ <property name="filter.abi" value="" />
+
<!-- Verbosity -->
<property name="verbose" value="false" />
<!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false'
@@ -153,6 +159,7 @@
basename="${ant.project.name}"
signed="@{sign.package}"
debug="${manifest.debuggable}"
+ abifilter="${filter.abi}"
verbose="${verbose}">
<file path="${intermediate.dex.file}" />
<sourcefolder path="${source.absolute.dir}" />
@@ -277,6 +284,7 @@
<echo>Packaging resources</echo>
<aaptexec executable="${aapt}"
command="package"
+ versioncode="${version.code}"
manifest="AndroidManifest.xml"
assets="${asset.absolute.dir}"
androidjar="${android.jar}"