I am having trouble creating an Ant build script for our production apps.
I have been reading a lot about Ant, and bb-ant-tools. I have followed many stackoverflow questions on Ant & BB (referenced below in comments to "link" the questions). I would like help with a script more complex than the usual "Hello World!" style apps. My current build process is run entirely in Eclipse, and done manually.
For this question, I would like to ask how to use Ant to build a project that uses 2 (or more) different library projects (which also need to be built), without using Eclipse at all?
I have Ant, bb-ant-tools installed. I have built & deployed on device a basic Hello World, using these tools following basic examples. I have created a build script, and some property files; but when I run the scripts, the end product does not run on the phone (phone UI freezes on the launch screen).
I have 3 build scripts, one for each library, and one for the main app. These are identical, except for the project name (and could be combined into one common imported script at some point). Each of the 3 java projects has an Ant properties file related to it. I also use 3 common properties files for defining constants, storing info on the JDE & the code signing password.
common.properties:
jde.home=C:/development/tools/bb-jde/jde4.5/components sigtool.jde = ${jde.home} sigtool.password = xxx_pass_xxx
project.properties (for SOAP library):
output=MySOAP type=midlet
project.properties (for internal SDK library):
output=MySDK type=midlet
Update 1: I have updated the library property files since initial post. Previously I set type=library
(based on RIM documentation). Based on my research outlined in this post (BlackBerry - use own JAR file in own project), I tried changing to type=midlet
. This gives better results (at least on my platform BB JDE 5.0).
project.properties (for my app):
output=MyApp title=App type=cldc vendor=Richard version=1.0.7 description=A nice app icon=icon.png
build.xml (all the same except for the name at the top, and the 2 library scripts do not have filesets declared inside import.jars):
<?xml version="1.0" encoding="ISO-8859-1"?> <project name="MyApp" default="build"> <!-- BLACKBERRY ANT TOOLS --> <property name="bb-ant-tools.home" location="C:/development/tools/bb-ant-tools" /> <taskdef resource="bb-ant-defs.xml" classpath="${bb-ant-tools.home}/bb-ant-tools.jar" /> <!-- CONFIG FILES --> <property file="${common.basedir}/common.properties" /> <property prefix="project" file="project.properties" /> <!-- FOLDERS --> <property name="dest.dir" location="build" /> <!-- this is empty in the library scripts --> <path id="import.jars"> <fileset dir="../MySDK/build" includes="*.jar" /> <fileset dir="../MySOAP/build" includes="*.jar" /> </path> <path id="src.files"> <fileset dir="src" includes="**/*" /> <fileset dir="res" includes="**/*" /> </path> <!-- TARGET ACTIONS --> <target name="build" depends=""> <mkdir dir="${dest.dir}" /> <!-- work around a bug requiring app icons to be in the output folder --> <copy file="${basedir}/res/icon.png" tofile="${dest.dir}/icon.png" /> <rapc jdehome="${jde.home}" output="${project.output}" destdir="${dest.dir}" > <import refid="import.jars" /> <src refid="src.files" /> <jdp file="${basedir}/project.properties" /> </rapc> </target> <target name="sign" depends="build"> <sigtool codfile="${dest.dir}/${project.output}.cod" jdehome="${sigtool.jde}" password="${sigtool.password}" /> </target> <target name="clean"> <delete dir="${dest.dir}" /> </target> </project>
Update 2: I have updated the build.xml
since the initial post. Target build
now copies the app icon into the build output folder (${dest.dir}
) to work around a bug in bb-ant-tools / rapc.
So this is a very simple Ant script, except:
- I would like to know how to trigger the sub-builds off from the main app build (my answer below deals with that).
- The big one, is that the resulting output from this does not work.
FWIW I have found the following popular resources, and list them so that they need not be added as answers, and to help anyone in the future looking for info:
and many answers here on stackoverflow - see my comments below
In order to maintain the resource structure instead of adding the 'res' folder as a source folder do the following:
Create a temporary jar file of all the resources using the ANT 'jar' command:
Add the temporary jar as a source element inside the 'src' element of the rapc command:
This is what I'm using across multiple projects.
This is the compilation code. We're compiling a few libraries and then the application, linking the just created libraries.
Then for signing:
And then uploading to our OTA server:
I saw question about how to save resource directory structure in Dhiral's comment to Joe's answer. Some days ago I found workaround here (Blackberry Development with Ant & Eclipse) in comments to post:
I hope you don't forget to ship your library cods with your app cod to the end user. Because otherwise app won't work.
About triggering library building - I prefer build libraries only when it's necessary - code or dependency changed.
About solution for you I would just have bat file where I will trigger ant three times with different build.xml files and proper current files (because you ant scripts have relative directories). So it would be like:
To answer my question about triggering builds for included projects, from my main build file, the solution is to use the
subant
task, which is a standard Ant command.For example, the below code (I forget where I copied it from, but its not mine, and it does work) will trigger the build.xml file in each of the folders supplied, and will run the
export-all
target within that build file.It requires a property called
project.deps
to be declared as a comma-separated list of folders. Thedirset
is defined by looking back one folder from the main build.xml, and looking for each of the subfolders inproject.deps
.Ant will then find the build.xml file in each of these folders, and run it, looking for the
export-all
target.Within each of the new
export-all
subtasks, the propertyexport.dir
will have been set, which is how you can pass info from the main build.xml into the subtasks.