PeterG PeterG - 1 year ago 52
Android Question

Create keystore file with one command

I have a script which creates and signs a keystore file for an android app.

It is working perfectly fine but i would rather have it run without human intervention

what i have to create the keystore:

keytool -genkey -v -keystore my-release-key.keystore
-alias alias_name -keyalg RSA -keysize 2048 -validity 10000

This then prompts me to enter the following values manually using the terminal: keystore password, full name , organisation unit, organisation name, city , state, county code, key password.

what i have to sign the app:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1
-keystore my-release-key.keystore my_application.apk alias_name

This then prompts me to enter passphrase for keystore.

Is there anyway i can pass these values in as parameters so the full script runs without anyother interaction needed?

PS: i'm using ubuntu 14.04 LTS.

Thanks For your time :)

Answer Source

You can do something like this to generate the keystore:

keytool -genkey -alias replserver \
    -keyalg RSA -keystore keystore.jks \
    -dname "CN=Mark Smith, OU=JavaSoft, O=Sun, L=Cupertino, S=California, C=US" \
    -storepass password -keypass password

Here is a good reference : And for the jarsigner there is "storepass" parameter for the keystore password. And if you put both in a script you should be good.