I want to customize the build process while continuing to use the Android Eclipse ADT plugin

The following builders are active with the ADT plug-in installed for the Android project:

  • Android Resource Manager
  • Android compiler
  • Java builder
  • Android Package Designer

Looking at the output directory, the following artifacts are created:

  • resources.ap_ (just APK / ZIP with resources and without code)
  • gen / R.java (auto-generated resource list)
  • .class Java bytecode files
  • classes.dex $ {ProjectName}
  • .apk

For my project, I automatically generate several code artifacts and generally need more tight control over the build process. At first I realized that the resource manager is responsible for creating resources.ap_, the precompiler created by R.java, java builder did the obvious, and then Android Package Builder created classes.dex, and then combined classes.dex and resources.ap_ to create an APK file .

I disabled the first two steps and created a custom pre-assembler in which a copy of resources.ap_ was installed, believing that this would be equivalent. There is no such luck.

Unfortunately, the final Android Package Builder seems to overlap resources directly from res / and ignore my .ap_ resources. In fact, the first two stages of the build seem to do nothing but generate R.java.

Here it becomes very problematic. If I disable the final build step and post my own APK file (with the same name), I get the following error:

[2011-02-27 20:25:28 - android-premium] ------------------------------ [2011-02-27 20:25:28 - android-premium] Android Launch! [2011-02-27 20:25:28 - android-premium] adb is running normally. [2011-02-27 20:25:28 - android-premium] Could not find android-premium.apk! 

So, I'm stuck: with Android Package Builder (which does not have a noticeable configuration) I have to provide separate files. / res /. Without this, I cannot run the project on the device (not from Eclipse).

Does anyone have any better ideas / experience in this space?

+7
source share
2 answers

As for Ant scripts, the following Ant template for creating an Android application (this can be useful for others trying to switch the Eclipse assembly to Ant, as it is much simpler and more transparent than the opaque version autogenerated using android tools):

 <property name="workspace.dir" value="/workspace" /> <property name="project.dir" location="." /> <property name="android-platform.name" value="android-1.5" /> <!-- Framework Paths --> <property name="android-sdk.dir" value="${workspace.dir}/EpicFramework/android-sdk"/> <property name="android-tools.dir" value="${android-sdk.dir}/tools" /> <property name="android-platform.dir" value="${android-sdk.dir}/platforms/${android-platform.name}" /> <property name="android-platform-tools.dir" value="${android-platform.dir}/tools"/> <property name="android-platform-jar" value="${android-platform.dir}/android.jar"/> <property name="android-framework-src.dir" value="${workspace.dir}/EpicFramework/EpicAndroid"/> <!-- Tool Binaries --> <property name="adb" value="${android-tools.dir}/adb"/> <property name="apkbuilder" value="${android-tools.dir}/apkbuilder"/> <property name="aapt" value="${android-platform-tools.dir}/aapt"/> <property name="dx" value="${android-platform-tools.dir}/dx"/> <!-- Project Paths --> <property name="src.dir" value="${project.dir}/src" /> <property name="gen.dir" value="${project.dir}/gen" /> <property name="res.dir" value="${project.dir}/res" /> <property name="lib.dir" value="${project.dir}/lib" /> <property name="build.dir" value="${project.dir}/bin" /> <property name="build.classes.dir" value="${build.dir}/classes" /> <property name="resources.file" value="${build.dir}/resources.ap_"/> <property name="dex.file" value="${build.dir}/classes.dex" /> <property name="debug-apk.file" value="${build.dir}/${ant.project.name}-debug.apk"/> <target name="dirs"> <echo>Creating output directories if needed...</echo> <mkdir dir="${res.dir}" /> <mkdir dir="${gen.dir}" /> <mkdir dir="${lib.dir}" /> <mkdir dir="${build.dir}" /> <mkdir dir="${build.classes.dir}" /> </target> <target name="android-resource-src" depends="dirs"> <echo>Generating R.java from the resources...</echo> <exec executable="${aapt}" failonerror="true"> <arg value="package" /> <arg value="-M" /> <arg path="AndroidManifest.xml" /> <arg value="-S" /> <arg path="${res.dir}" /> <arg value="-I" /> <arg path="${android-platform-jar}" /> <arg value="-m" /> <arg value="-J" /> <arg path="${gen.dir}" /> </exec> </target> <target name="android-compile" depends="android-resource-src"> <echo>Compiling java files into class files...</echo> <javac encoding="ascii" target="1.5" debug="true" extdirs="" destdir="${build.classes.dir}" includeAntRuntime="false" bootclasspath="${android-platform-jar}"> <src path="${android-framework-src.dir}" /> <src path="${src.dir}" /> <src path="${gen.dir}" /> <classpath> <fileset dir="${lib.dir}" includes="*.jar"/> </classpath> </javac> </target> <target name="android-dex" depends="android-compile"> <echo>Converting compiled files and 3rd party libraries into ${dex.file} ...</echo> <apply executable="${dx}" failonerror="true" parallel="true"> <arg value="--dex" /> <arg value="--output=${dex.file}" /> <arg path="${build.classes.dir}" /> <fileset dir="${lib.dir}" includes="*.jar"/> </apply> </target> <target name="android-package-resources"> <echo>Packaging Android resources into ${resources.file} ...</echo> <exec executable="${aapt}" failonerror="true"> <arg value="package" /> <arg value="-M" /> <arg path="AndroidManifest.xml" /> <arg value="-S" /> <arg path="./res" /> <arg value="-I" /> <arg path="${android-platform-jar}" /> <arg value="-f" /> <arg value="-F" /> <arg value="${resources.file}" /> </exec> </target> <target name="android-debug" depends="android-dex, android-package-resources"> <echo>Packaging app and signing it with the debug key</echo> <exec executable="${apkbuilder}" failonerror="true"> <arg value="${debug-apk.file}" /> <arg value="-d" /> <arg value="-z" /> <arg value="${resources.file}/" /> <arg value="-f" /> <arg value="${dex.file}" /> </exec> </target> <target name="android-release" depends="android-dex, android-package-resources"> <echo>Packaging App without signing, so that it can be signed with the official publishing key ...</echo> <exec executable="${apkbuilder}" failonerror="true"> <arg value="${release-apk.file}" /> <arg value="-u" /> <arg value="-d" /> <arg value="-z" /> <arg value="${resources.file}/" /> <arg value="-f" /> <arg value="${dex.file}" /> </exec> <echo>All generated packages need to be signed with jarsigner before they are published.</echo> </target> <target name="android-install" depends="android-debug"> <echo>Removing all com.epicapplications APK files from default emulator ...</echo> <exec executable="${adb}" inputstring="echo hi; rm -f /data/app/com.epicapplications.*; exit; "> <arg value="shell"/> </exec> <echo>Installing ${debug-apk.file} onto default emulator...</echo> <exec executable="${adb}" failonerror="true"> <arg value="install" /> <arg value="-r" /> <arg path="${debug-apk.file}" /> </exec> </target> 

I am looking to be able to use all or fragments of this Ant build script, but still have Eclipse integration to run and debug the application.

+12
source

We used Ant scripts to complete the build process for Android projects, others also used Maven. They help as soon as you can script to run them every day as part of nightly builds, as part of your CI build system. At an advanced level, you can script to do this to build releases with release tags, pre-compiling and then compiling the changes and signing AndroidManifest.xml.

+2
source

All Articles