Skip to content

Creating a Release APK

HeRo002 edited this page Jun 28, 2020 · 21 revisions
Clone this wiki locally

Instructions for creating a signed, release APK, suitable for the Google Play Store

To make things easier, you should do all these commands in the same terminal, especially the steps 2 and 3 as step 3 depends on the exported variables, and export only affect the current shell (the program that runs in the terminal) session. Step 1 is only needed the first time you do a release, as you'll reuse your keys for subsequent releases, make sure not to erase your ~/keystores directory, or you won't be able to release updates to your app.

  1. You need to know about the Android APK signing process. If you do not, start by reading the official Sign Your App documentation.

  2. You need to create the key:

     $ mkdir -p ~/keystores/
     $ keytool -genkey -v -keystore ~/keystores/<your-new-key>.keystore -alias <your-key-alias> -keyalg RSA -keysize 2048 -validity 10000
    

[ Addition by HeRo002, Feb. 25, 2020:

'keytool' does not like non-English characters in passwords.

'keytool' says: Warning:

The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using:

    $ keytool -importkeystore -srckeystore ~/keystores/<your-new-key>.keystore -destkeystore ~/keystores/<your-new-key>.keystore -deststoretype pkcs12

But that form of the command only seems to work if the 2 passwords are identical. ]

  1. Then export some variables:

     $ export P4A_RELEASE_KEYSTORE=~/keystores/<your-new-key>.keystore
     $ export P4A_RELEASE_KEYSTORE_PASSWD=android
     $ export P4A_RELEASE_KEYALIAS_PASSWD=android
     $ export P4A_RELEASE_KEYALIAS=<your-key-alias>
    

[ Addition by HeRo002, Feb. 28, 2020:

NB! Replace line 2 and 3 in the above with this...:

    $ export P4A_RELEASE_KEYSTORE_PASSWD="<your-keystore-password>"
    $ export P4A_RELEASE_KEYALIAS_PASSWD="<your-key-alias-password>"

PS: It seems that people generally prefer to use 2 identical passwords. ]

  1. Make release apk (will be signed automatically) using the :

     $ cd <your-project-folder>
     $ buildozer -v android release
    

[ HeRo002, edited again March 4, 2020:

Experience of mine and others show that the following step 4 corrupts the APK file! You cannot 'zipalign' it AFTER signing it. Simply skip Step 4. You will get a warning in Google Play Console that the APK package is not optimized, but that is not a real problem...

  1. Optimize it:

     $ ~/.buildozer/android/platform/android-sdk-20/build-tools/23.0.1/zipalign -v 4 ./bin/Your-App-0.1-release.apk ./bin/Your-App-0.1-release-optimized.apk
    

]