With the release of our new PDF to Android Viewer we needed to have a reliable way of building the resulting applications for our customers to test and use. For this we use Ant as it’s the default way of building Android applications with the Android SDK, there are depreciated libraries still packaged with the SDK but there doesn’t seem to be any documentation about using them for recent versions of Android.
However, in order to install an application on an Android device the .apk file will need to be signed, this is to ensure that applications always come from the same source and can be trusted, similar to how a Java applet needs to be signed in order to access the local file system, only much more strict.
When developing using Eclipse, IntelliJ, NetBeans or any other IDE your application is signed using a debug key so you can deploy it onto your own devices for testing. This key isn’t suitable for actually releasing applications and is not allowed to be used when publishing to the Play Store.
Those familiar with pure Java and Java applets may also be familiar with the keytool and jarsigner tools that can do these operations, but you can also do the same operations in Ant by appending they keystore file location and alias to use to your ant.properties file so it looks something like this:
# This file is used to override default values used by the Ant build system. # # This file must be checked into Version Control Systems, as it is # integral to the build system of your project. # This file is only used by the Ant script. # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and # 'key.alias' for the name of the key to use. # The password will be asked during the build when you use the 'release' target. key.store=path/to/keystore-file key.alias=my-alias
A feature that is explained within the comments of the file.
However if you read the comments further you will see that on each build it will ask you for your password. To ensure that the conversion process can be automated and to remove this complexity we don’t want to be typing in our details after every conversion.
We can do this by adding in the passwords to this file, a feature that doesn’t seem to be explained on the Android documentation page that deals with signing your applications.What you add to the end of the previously mentioned file is simply:
One site that I found that listed this feature has some slightly out of date/incorrect information but you can find it here. It also isn’t updated any more but still has some useful information for anyone interested in Android development, just be aware that the Android platform is always changing so many things become obsolete, but it’s still worth checking out, especially if you want to keep backwards compatibility with older versions of the Android OS.
Hopefully you’ve found this blog post interesting and useful, if you have anything to share about automating your Android build processes feel free to leave a comment below.
This post is part of our “Android Articles Index” series. In these articles, we aim to explore android in different ways. Have a look!