April 11, 2014
In my last post about releasing for android, I had a long list of commands that you had to run, to finally create a releasable apk file. It looked something like this:
ant release cd bin jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /Users/username/Documents/path/to/my-release-key.keystore AppName-release-unsigned.apk app_name jarsigner -verify -verbose -certs AppName-release-unsigned.apk zipalign -v 4 AppName-release-unsigned.apk AppName.apk
Well, that’s kinda complicated. And it turns out, there’s any easy way to do all of this with just this:
What?!? How can the first command do the same thing as 5 commands?
The answer is with a few configuration files that will let ant know where the keystore file is and what its passwords are.
build.xml and make sure that it has this line:
<property file="ant.properties" />
And this line:
<import file="custom_rules.xml" optional="true" />
ant.properties and make sure it looks like this:
key.store can either be an absolute path (like the example above), or a relative path like this:
custom_rules.xml (create it, if it doesn’t exist) and make sure it looks like this:
<?xml version="1.0" encoding="UTF-8"?> <project name="custom_rules" default="help"> <property file="../../../secure.properties" /> </project>
This will point to a custom file that will store your passwords for your keystore file. In this example, I’m pointing 3 directories above the current directory. Since this file will contain sensitive information, it’s best to keep it outside of your source control. You can either put it outside of your source control as I did, you you can ignore the file in your
secure.properties file, in the location of your choice and set it up like this. It contains the password for your key store and alias.
And there you have it. You should just be able to run
and you should get a final apk output in the bin directory. Just remember to go into your
AndroidManifest and set debuggable to false.
Written by Adam Garrett-Harris who lives and works in Silicon Slopes. You should follow him on Twitter