Here at Splick-it, we build apps. Lots of apps. When you look at the time it takes to take an app from a code base and a set of assets to a built and tested product ready for release, you can’t help but think that there must be a better way, a more automated solution perhaps. That problem is exactly the one that I have been trying to tackle and I am here to share a few bits of knowledge that I have picked up along the way. This week’s post discusses the automation of creating build files and actually building Android apps. The goal of the first step was to take this process which I currently manage with IntelliJ and run it via command line processes.
We structure our Android applications with a core code base and create different builds of that base according to brand resources. The first step is to identify your library project and set it up as so. In the project.properties file of the core project, you will see the following line:
Make sure this flag is set to true to indicate that this is a library project. As a side note, the Android build process combines these external libraries with the project source after the two have been compiled, turning them into Dalvik byte code (more info on the build process here: http://developer.android.com/tools/building/index.html).
The second step is to create a build file for your project. Run the following command from the root of your main project (NOT the library project):
android update project -p ./ (path to your project, use this if compiling inside project) -t insertTargetSDKHere -l /path/to/your/library
The -p flag is crucial and points to the project, the -t flag sets the target SDK and the -l flag points to your dependency (the library project). Similarly, we will create a build file for the library using:
android update lib-project -t insertTargetSDKHere
Next we build the project with ant (by running: ant debug) and it should build correctly. This is where the problems started for me. Our library contains all the business logic, with the main projects containing assets and configurations. When building with ant, I kept receiving the error that there was no /src. The solution was very simple: include an empty /src folder in the root of the main project.
After that, update again with:
android update project -t 2 -p ./ -l path/to/library
Finally, start the emulator and install from the /bin with:
adb install .apk
I hope this helps anyone trying to incorporate custom libraries into their code. Some resources I found exceptionally helpful were the Android developer site, specifically the command line resources (http://developer.android.com/tools/projects/projects-cmdline.html) and the project type explanations page (http://developer.android.com/tools/projects/index.html).
Image courtesy of Stuart Miles/FreeDigitalPhotos.net