I'm trying to get a handle on this whole "Ant" buildsystem thing. I've created a build.xml that Android natively gives me by using the command: android update project -p .
.
While this has given me a template build.xml file, I would like a couple more options. Specifically, I would like to be able to JAR and/or Compile my project; preferably with a version number.
Bonus Question: How can I exclude files from my JAR build. For example, I have one activity that I've used to test my functionality, but I don't want that to be included in the final JAR.
My build.xml file that Android has given me is Gisted here since it's pretty long (mostly comments).
EDIT: I'm also using IntelliJ so no Eclipse specifics, please!
Specifically, I would like to be able to JAR and/or Compile my project; preferably with a version number.
In Android, version numbers are for apps, not JARs.
That being said, adding a jar
target is a matter of adding this to your build.xml
file towards the bottom:
<target name="jar" depends="debug">
<jar
destfile="bin/whatever-you-want-to-call-the.jar"
basedir="bin/classes"
/>
</target>
Then, run ant jar
to compile and package the JAR file.
You will see this pattern in most of the reusable Android components in my GitHub area (see the cwac-
repos).
Bonus Question: How can I exclude files from my JAR build. For example, I have one activity that I've used to test my functionality, but I don't want that to be included in the final JAR.
Use excludes
or excludesfile
, as described in the jar
Ant task documentation.
For reuse of Android and non-android projects I would suggest you take a look at the Android Maven Plugin. It takes advantage of dependency management and other powerful features of Maven and will be much more suitable to what you want to do.
Checkout the webpage and documentation on it and maybe the chapter about Android development in Maven : The Complete Reference I wrote to get a bit more understanding as well as have something to look at about Maven.
The Android plugin supports reuse for normal jar artifacts and if there are Android dependencies within the code you can use apklib projects. Lots of projects like Roboguice, robolectric, actionbarsherlock and others use this feature successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With