Search code examples
androidcordovaandroid-build

Create android keystory/ private key command line


I have built my application with cordova command line. Now I understand that in order to release I need to get Keystore and private key. In android documentation I see that I need to do it on Android studio. http://developer.android.com/tools/publishing/app-signing.html But if I get it correctly I will need to build the project with android studio and not in command line. But I thought that the recommended form was to work with command line in cordova.

Is it possible to create keystore/ private key in command line? If not is it possible to open a project that I have built in codova with Adnroid studio, create keystore/ private key and then build it again in cordova.

Also do you need to create a different keystore/ private key for each project?


Solution

  • Check this section.
    "You do not need Android Studio or the ADT plugin for Eclipse to sign your app"

    How to sign your app manually.

    Generate a private key using keytool. For example:

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

    This example prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app.

    Compile your app in release mode to obtain an unsigned APK.

    Sign your app with your private key using jarsigner:

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

    This example prompts you for passwords for the keystore and key. It then modifies the APK in-place to sign it. Note that you can sign an APK multiple times with different keys.

    Verify that your APK is signed. For example:

    $ jarsigner -verify -verbose -certs my_application.apk
    

    Align the final APK package using zipalign.

    $ zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
    

    zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app.