Lyndon Armitage Lyndon is a Developer at IDR Solutions. He currently focuses mostly on the JavaScript in the Viewer and PDF to HTML5 Converter and also the Android PDF Viewer. He gave a short talk at the GlassFish UnConference before JavaOne 2012. Outside of IDR Solutions he has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

Automatically Signing Android Applications

2 min read

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:

key.store.password=store-password
key.alias.password=alias-password

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!

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the  Blog RSS.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Lyndon Armitage Lyndon is a Developer at IDR Solutions. He currently focuses mostly on the JavaScript in the Viewer and PDF to HTML5 Converter and also the Android PDF Viewer. He gave a short talk at the GlassFish UnConference before JavaOne 2012. Outside of IDR Solutions he has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

JavaOne Exhibitor Planning with Trello

In October this year we attended and exhibited at the world’s biggest Java conference (JavaOne) which is based in San Francisco. When exhibiting at...
Sophia Matarazzo
3 min read

4 ways to get the most from Android Developer…

I like to get down to coding and lock myself away so I can focus on getting things done without interruption. But I also...
Mark Stephens
1 min read

Top 9 Android Apps and IDE for Java Coders…

Recently at IDRsolutions my collegues have spent a lot of time traveling to different conferences such as Oracle Code One and DevFest. One of the...
Alex Marshall
4 min read

Leave a Reply

Your email address will not be published. Required fields are marked *