Creating an Ant-based application template manually
Let's start with the lowest level and create a template for our applications buildable with Apache Ant. Every Android application which is to be built using Apache Ant should contain a predefined directories structure and configuration .xml files. This is usually done using Android SDK tools and IDEs. We will explain how to do it by hand to let you know the machinery behind the curtains.
The directory structure of our minimalistic project looks like the following screenshot (see the source code bundle for the complete source code):
We need to create the following files within this directory structure:
res/drawable/icon.pngres/values/strings.xmlsrc/com/packtpub/ndkmastering/App1Activity.javaAndroidManifest.xmlbuild.xmlproject.properties
The icon icon.png should be there, and currently contains a dummy image of an Android application:
The file strings.xml is required to make use of the Android localization system. In the manifest AndroidManifest.xml, we use the string parameter app_name instead of the actual application name. The file strings.xml resolves this parameter into a human readable string:
The Java source code of the minimal buildable application is in the App1Activity.java file:
The rest three files, AndroidManifest.xml, build.xml, and project.properties, contain the description of the project necessary for Ant to build it.
The manifest AndroidManifest.xml is as follows:
Our application will require Android 4.4 (API Level 19) and is tested with Android 6.0 (API Level 23):
Most of the examples in this book will require OpenGL ES 3. Let's mention it here:
Here is the name of the main activity:
We want a fullscreen application in the landscape orientation:
Our application can be started from the system launcher. The displayable name of the application is stored in the app_name parameter:
The file build.xml is much simpler and will resemble mostly what Android tools would generate:
There is a difference to Android SDK Tools, since we don't use ant.properties here. This was done just for the sake of simplicity and just has an educational purpose.
The same situation exists with the file project.properties, which contains platform-specific declarations:
Now, our first application (which does not even contain any native code yet) is ready to be built. Use the following one-liner to build it:
If everything was done correctly, you should see the tail of the output similar to the following:
To install an .apk file from the command line, run adb install -r bin/App1-debug.apk to install the freshlybuilt .apk on your device. Start the application from your launcher (AntApp1) and enjoy the black screen. You can use the BACK key to exit the application.