(Still) build Android apps with ant and Eclipse
Android ant support
There are legitimate reasons to still build Android apps using ant
.
First of all, you may be responsible for supporting a legacy project with very limited new development.
Migrating such a project to AndroidStudio and gradle
may require more effort than you can spare
(especially as you’d also have to migrate the project structure).
However, there are a few quirks that you have to keep in mind. The following setup works for us:
Platform setup
Tools 25.2.5 seem to be the last version with ant support. We’re using build-tools 25.0.3,
but more modern versions also should work.
For installing the current Android target 31 you’ll have to use the sdkmanager from tools dir,
otherwise you’ll get a target not found
error.
To enforce the use of build-tools 25.0.3, you can put the following line in your project.properties
file:
Use patched build.xml
The build.xml file from the ${ANDROID_HOME}/tools/ant
dir does not work anymore for modern targets.
Especially, the code signing process has to be adapted. You can use our patched
build-android-sdk.xml.
This file has to be referenced from your build.xml
file (near the end of the file) like this:
Call ant
(Limited) Eclipse support
Support for Eclipse using Andmore from Eclipse Marketplace seems to be abandoned. Currently we can’t recommend this approach.
However, some of our developers use a configuration which allows at least editing Android apps within Eclipse.
For this, you have to patch org.eclipse.andmore.base_0.5.1.201701251432.jar
with some classes from an ancient Oracle Java 8 release.
Where org.eclipse.andmore.base_0.5.1.201701251432.jar
is found, depends on your installation – usually either in Eclipse/plugins
or in your home dir in .p2/pool/plugins
.
You’ll still get an ugly error when compiling files (“Errors occurred during the build.”). To avoid this, you can check
Skip packaging and dexing until export or launch
in Eclipse Android preferences.
Probably you can even restore packaging and dexing by including crypto classes from sun.misc
, but this is beyond the scope of this snippet.
tom
ANDROID
android eclipse