Search code examples
javaandroidlinuxcommand-line-interfacekeystore

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 :)


Solution

  • 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 : https://pubs.vmware.com/continuent/tungsten-replicator-3.0/deployment-ssl-stores.html. And for the jarsigner there is "storepass" parameter for the keystore password. And if you put both in a script you should be good.