aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-05-06 18:08:46 -0700
committerXavier Ducrohet <xav@android.com>2010-05-06 18:15:18 -0700
commit0a958e76e9406faed2c76d44557c678a6caa7081 (patch)
treed418c3bc29523a757e24e34a1d252ab403cac172
parent360baa4689cb7afabf758066263ccab299dfef2c (diff)
downloadsdk-0a958e76e9406faed2c76d44557c678a6caa7081.zip
sdk-0a958e76e9406faed2c76d44557c678a6caa7081.tar.gz
sdk-0a958e76e9406faed2c76d44557c678a6caa7081.tar.bz2
Add support for code-less project.
Change-Id: I09e8e5b40df3b8da4b34fe4f000e98263ea5bc55
-rw-r--r--anttasks/src/com/android/ant/ApkBuilderTask.java41
-rw-r--r--anttasks/src/com/android/ant/SetupTask.java7
-rw-r--r--files/ant/ant_rules_r3.xml140
-rw-r--r--templates/build.alias.template23
4 files changed, 133 insertions, 78 deletions
diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java
index a49c2c5..9e3c8e4 100644
--- a/anttasks/src/com/android/ant/ApkBuilderTask.java
+++ b/anttasks/src/com/android/ant/ApkBuilderTask.java
@@ -39,9 +39,11 @@ public class ApkBuilderTask extends Task {
private boolean mVerbose = false;
private boolean mSigned = true;
private boolean mDebug = false;
+ private boolean mHasCode = true;
private String mAbiFilter = null;
private final ArrayList<Path> mZipList = new ArrayList<Path>();
+ private final ArrayList<Path> mDexList = new ArrayList<Path>();
private final ArrayList<Path> mFileList = new ArrayList<Path>();
private final ArrayList<Path> mSourceList = new ArrayList<Path>();
private final ArrayList<Path> mJarfolderList = new ArrayList<Path>();
@@ -129,6 +131,15 @@ public class ApkBuilderTask extends Task {
}
/**
+ * Sets the hascode attribute. Default is true.
+ * If set to false, then <dex> and <sourcefolder> nodes are ignored and not processed.
+ * @param hasCode the value of the attribute.
+ */
+ public void setHascode(boolean hasCode) {
+ mHasCode = hasCode;
+ }
+
+ /**
* Returns an object representing a nested <var>zip</var> element.
*/
public Object createZip() {
@@ -138,6 +149,17 @@ public class ApkBuilderTask extends Task {
}
/**
+ * Returns an object representing a nested <var>dex</var> element.
+ * This is similar to a nested <var>file</var> element, except when {@link #mHasCode}
+ * is <code>false</code> in which case it's ignored.
+ */
+ public Object createDex() {
+ Path path = new Path(getProject());
+ mDexList.add(path);
+ return path;
+ }
+
+ /**
* Returns an object representing a nested <var>file</var> element.
*/
public Object createFile() {
@@ -210,11 +232,22 @@ public class ApkBuilderTask extends Task {
}
}
+ // only attempt to add Dex files if hasCode is true.
+ if (mHasCode) {
+ for (Path pathList : mDexList) {
+ for (String path : pathList.list()) {
+ mArchiveFiles.add(ApkBuilderImpl.getInputFile(path));
+ }
+ }
+ }
+
// now go through the list of file to directly add the to the list.
- for (Path pathList : mSourceList) {
- for (String path : pathList.list()) {
- ApkBuilderImpl.processSourceFolderForResource(new File(path),
- mJavaResources);
+ if (mHasCode) {
+ for (Path pathList : mSourceList) {
+ for (String path : pathList.list()) {
+ ApkBuilderImpl.processSourceFolderForResource(new File(path),
+ mJavaResources);
+ }
}
}
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java
index 85ebea1..0fbd3a0 100644
--- a/anttasks/src/com/android/ant/SetupTask.java
+++ b/anttasks/src/com/android/ant/SetupTask.java
@@ -107,7 +107,7 @@ public final class SetupTask extends ImportTask {
*/
private final static int ANT_COMPATIBILITY_RANGES[][] = new int[][] {
new int[] { 1, 1 },
- new int[] { 2, 3 },
+ new int[] { 2, ANT_RULES_MAX_VERSION },
};
private boolean mDoImport = true;
@@ -357,6 +357,11 @@ public final class SetupTask extends ImportTask {
}
}
+ /**
+ * Returns the revision number of a newer but still compatible Ant rules available in the
+ * tools folder of the SDK, or -1 if none is found.
+ * @param rulesRev the revision of the rules file on which compatibility is based.
+ */
private int getAntRulesFromTools(int rulesRev) {
for (int[] range : ANT_COMPATIBILITY_RANGES) {
if (range[0] <= rulesRev && rulesRev <= range[1]) {
diff --git a/files/ant/ant_rules_r3.xml b/files/ant/ant_rules_r3.xml
index 775c83c..ed53c05 100644
--- a/files/ant/ant_rules_r3.xml
+++ b/files/ant/ant_rules_r3.xml
@@ -43,7 +43,10 @@
output="manifest.package" />
<!-- Value of the debuggable attribute (Application node) extracted from manifest file -->
<xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable"
- output="manifest.debuggable" default="false"/>
+ output="manifest.debuggable" default="false"/>
+ <!-- Value of the debuggable attribute (Application node) extracted from manifest file -->
+ <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode"
+ output="manifest.hasCode" default="true"/>
<!-- Input directories -->
<property name="source.dir" value="src" />
@@ -196,10 +199,11 @@
signed="@{sign.package}"
debug="${manifest.debuggable}"
abifilter="${filter.abi}"
- verbose="${verbose}">
- <file path="${intermediate.dex.file}" />
- <sourcefolder path="${source.absolute.dir}" />
- <sourcefolder refid="android.libraries.src" />
+ verbose="${verbose}"
+ hascode="${manifest.hasCode}">
+ <dex path="${intermediate.dex.file}"/>
+ <sourcefolder path="${source.absolute.dir}"/>
+ <sourcefolder refid="android.libraries.src"/>
<jarfolder path="${external.libs.absolute.dir}" />
<jarfolder refid="android.libraries.libs" />
<nativefolder path="${native.libs.absolute.dir}" />
@@ -247,9 +251,13 @@
<echo>Creating output directories if needed...</echo>
<mkdir dir="${resource.absolute.dir}" />
<mkdir dir="${external.libs.absolute.dir}" />
- <mkdir dir="${gen.absolute.dir}" />
<mkdir dir="${out.absolute.dir}" />
- <mkdir dir="${out.classes.absolute.dir}" />
+ <if condition="${manifest.hasCode}">
+ <then>
+ <mkdir dir="${gen.absolute.dir}" />
+ <mkdir dir="${out.classes.absolute.dir}" />
+ </then>
+ </if>
</target>
<!-- empty default pre-build target. Create a similar target in
@@ -258,28 +266,42 @@
<!-- Generates the R.java file for this project's resources. -->
<target name="-resource-src" depends="-dirs, -pre-build">
- <echo>Generating R.java / Manifest.java from the resources...</echo>
- <aaptexec executable="${aapt}"
- command="package"
- verbose="${verbose}"
- manifest="AndroidManifest.xml"
- androidjar="${android.jar}"
- rfolder="${gen.absolute.dir}">
- <res path="${resource.absolute.dir}" />
- </aaptexec>
+ <if condition="${manifest.hasCode}">
+ <then>
+ <echo>Generating R.java / Manifest.java from the resources...</echo>
+ <aaptexec executable="${aapt}"
+ command="package"
+ verbose="${verbose}"
+ manifest="AndroidManifest.xml"
+ androidjar="${android.jar}"
+ rfolder="${gen.absolute.dir}">
+ <res path="${resource.absolute.dir}" />
+ </aaptexec>
+ </then>
+ <else>
+ <echo>hasCode = false. Skipping...</echo>
+ </else>
+ </if>
</target>
<!-- Generates java classes from .aidl files. -->
<target name="-aidl" depends="-dirs">
- <echo>Compiling aidl files into Java classes...</echo>
- <apply executable="${aidl}" failonerror="true">
- <arg value="-p${android.aidl}" />
- <arg value="-I${source.absolute.dir}" />
- <arg value="-o${gen.absolute.dir}" />
- <fileset dir="${source.absolute.dir}">
- <include name="**/*.aidl" />
- </fileset>
- </apply>
+ <if condition="${manifest.hasCode}">
+ <then>
+ <echo>Compiling aidl files into Java classes...</echo>
+ <apply executable="${aidl}" failonerror="true">
+ <arg value="-p${android.aidl}" />
+ <arg value="-I${source.absolute.dir}" />
+ <arg value="-o${gen.absolute.dir}" />
+ <fileset dir="${source.absolute.dir}">
+ <include name="**/*.aidl" />
+ </fileset>
+ </apply>
+ </then>
+ <else>
+ <echo>hasCode = false. Skipping...</echo>
+ </else>
+ </if>
</target>
<!-- empty default pre-compile target. Create a similar target in
@@ -289,29 +311,39 @@
<!-- Compiles this project's .java files into .class files. -->
<target name="compile" depends="-resource-src, -aidl, -pre-compile"
description="Compiles project's .java files into .class files">
- <!-- If android rules are used for a test project, its classpath should include
- tested project's location -->
- <condition property="extensible.classpath"
- value="${tested.project.absolute.dir}/bin/classes" else=".">
- <isset property="tested.project.absolute.dir" />
- </condition>
- <condition property="extensible.libs.classpath"
- value="${tested.project.absolute.dir}/libs" else="./libs">
- <isset property="tested.project.absolute.dir" />
- </condition>
- <javac encoding="ascii" target="1.5" debug="true" extdirs=""
- destdir="${out.classes.absolute.dir}"
- bootclasspathref="android.target.classpath"
- verbose="${verbose}" classpath="${extensible.classpath}"
- classpathref="android.libraries.jars">
- <src path="${source.absolute.dir}" />
- <src path="${gen.absolute.dir}" />
- <src refid="android.libraries.src" />
- <classpath>
- <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
- <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
- </classpath>
- </javac>
+ <if condition="${manifest.hasCode}">
+ <then>
+ <!-- If android rules are used for a test project, its classpath should include
+ tested project's location -->
+ <condition property="extensible.classpath"
+ value="${tested.project.absolute.dir}/bin/classes"
+ else=".">
+ <isset property="tested.project.absolute.dir" />
+ </condition>
+ <condition property="extensible.libs.classpath"
+ value="${tested.project.absolute.dir}/libs"
+ else="./libs">
+ <isset property="tested.project.absolute.dir" />
+ </condition>
+ <javac encoding="ascii" target="1.5" debug="true" extdirs=""
+ destdir="${out.classes.absolute.dir}"
+ bootclasspathref="android.target.classpath"
+ verbose="${verbose}"
+ classpath="${extensible.classpath}"
+ classpathref="android.libraries.jars">
+ <src path="${source.absolute.dir}" />
+ <src path="${gen.absolute.dir}" />
+ <src refid="android.libraries.src" />
+ <classpath>
+ <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
+ <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
+ </classpath>
+ </javac>
+ </then>
+ <else>
+ <echo>hasCode = false. Skipping...</echo>
+ </else>
+ </if>
</target>
<!-- empty default post-compile target. Create a similar target in
@@ -319,8 +351,16 @@
<target name="-post-compile"/>
<!-- Converts this project's .class files into .dex files -->
- <target name="-dex" depends="compile, -post-compile" unless="do.not.compile">
- <dex-helper />
+ <target name="-dex" depends="compile, -post-compile"
+ unless="do.not.compile">
+ <if condition="${manifest.hasCode}">
+ <then>
+ <dex-helper />
+ </then>
+ <else>
+ <echo>hasCode = false. Skipping...</echo>
+ </else>
+ </if>
</target>
<!-- Puts the project's resources into the output package file
diff --git a/templates/build.alias.template b/templates/build.alias.template
deleted file mode 100644
index d051405..0000000
--- a/templates/build.alias.template
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-ALIAS PROJECTS ARE CURRENT NOT SUPPORTED.
-THIS FILE IS CURRENTLY BROKEN AND SHOULD NOT BE USED.
--->
-<project name="PROJECT_NAME" default="package">
-
- <!-- The build.properties file can be created by you and is never touched
- by activitycreator. If you want to manually set properties, this is
- the best place to set them. -->
- <property file="build.properties" />
-
- <!-- The default.properties file is created and updated by activitycreator.
- It will set any properties not already defined by build.properties. -->
- <property file="default.properties" />
-
- <!-- ************************************************************************************* -->
- <!-- Import the default Android build rules.
- This requires ant 1.6.0 or above. -->
-
- <import file="${sdk.dir}/tools/lib/alias_rules.xml" />
-
-</project>