Automation For Android Release Build
Solution 1:
Assuming you're using recent Android tools, say v9 or v10.
If you look at tools/ant/main_rules.xml
in the Android SDK directory:
<!-- called through target 'release'. Only executed if the keystore and
key alias are known but not their password. --><targetname="-release-prompt-for-password"if="has.keystore"unless="has.password"><!-- Gets passwords --><inputmessage="Please enter keystore password (store:${key.store}):"addproperty="key.store.password" /><inputmessage="Please enter password for alias '${key.alias}':"addproperty="key.alias.password" /></target><!-- called through target 'release'. Only executed if there's no
keystore/key alias set --><targetname="-release-nosign"unless="has.keystore"><echo>No key.store and key.alias properties found in build.properties.</echo><echo>Please sign ${out.unsigned.file} manually</echo><echo>and run zipalign from the Android SDK tools.</echo></target>
Searching the XML file for has.keystore
reveals:
<!-- properties for signing in release mode --><conditionproperty="has.keystore"><and><issetproperty="key.store" /><lengthstring="${key.store}"when="greater"length="0" /><issetproperty="key.alias" /></and></condition><conditionproperty="has.password"><and><issetproperty="has.keystore" /><issetproperty="key.store.password" /><issetproperty="key.alias.password" /></and></condition>
So I'd assume you have to pass in four defines to the build.xml: key.store
, key.alias
, key.store.password
, key.alias.password
.
And remember not to pass those defines on the command line for security reasons. :)
Solution 2:
Gradle-based builds
1) Create a secure.properties
file to contain your passwords:
key.store.password=<your keystore password>
key.alias.password=<your alias password>
You probably don't want it under version control, which is why we're putting the passwords in a separate *.properties
file. If you don't mind having your passwords under version control, you can enter your passwords directly into build.gradle
, but that's not recommended, so I'm not directly showing that.
2) Set up your build.gradle
as follows:
PropertiessecureProperties=newProperties()
secureProperties.load(newFileInputStream("secure.properties"))
android {
signingConfigs {
release {
storeFile file("<path to your keystore>")
storePassword secureProperties['key.store.password']
keyAlias "<alias name>"
keyPassword secureProperties['key.alias.password']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
And that's it. ./gradlew assembleRelease
now builds and signs my APK without prompting for my password.
Ant-based builds
1) Create a secure.properties
file to contain your passwords:
key.store.password=<your keystore password>
key.alias.password=<your alias password>
You probably don't want it under version control, which is why we're not putting the passwords in one of the existing *.properties
files. If you don't mind having your passwords under version control, put these two lines in ant.properties
and you're done.
2) Create a custom_rules.xml
file to tell the build system about your secure.properties
file.
<?xml version="1.0" encoding="UTF-8"?><projectname="custom_rules"default="help"><propertyfile="secure.properties" /></project>
I'm not familiar with this build system, so I'm not sure about the project
element's name
or default
properties, but I believe what I chose should work for everybody.
2b) Any recent version of the Android SDK tools should be good to go, but if for some reason your build.xml
file doesn't contain the following, you should add it:
<import file="custom_rules.xml" optional="true" />
And that should be it. ant release
now builds and signs my APK without prompting for my password.
Solution 3:
You can define your keystore configure in your project.properties in your project folder. Just like this
key.store=/path/to/your/keystore
key.alias=yourkeyalias
key.store.password=yourkeystorepassword
key.alias.password=yourkeyaliaspassword
Solution 4:
Just a note... I didn't want to set the passwords in a props file and by default your password will be echoed on the command line which is also a concern. Adding use of SecureInputHandler to you main_rules.xml works so that your password isn't exposed on the command line.
<targetname="-release-prompt-for-password"if="has.keystore"unless="has.password"><!-- Gets passwords --><inputmessage="Please enter keystore password (store:${key.store}):"addproperty="key.store.password" ><handlerclassname="org.apache.tools.ant.input.SecureInputHandler" /></input><inputmessage="Please enter password for alias '${key.alias}':"addproperty="key.alias.password" ><handlerclassname="org.apache.tools.ant.input.SecureInputHandler" /></input></target>
Solution 5:
have a look at this article, especially where it starts mentioning key.store.password
. I've used it without troubles.
Basically you should create some secure.properties
file local to your (build) machine, that has to be kept relatively safe, e.g. not accessible to everyone or not stored for everyone in source control. That file stores the passwords as properties with the right names, and it's imported into project ANT build file.
Post a Comment for "Automation For Android Release Build"