How to generate platform key for Signing App using Android Studio ?

If we are working on Android platform and require certain applications to be signed using platform key, the one option for us is to integrate the application into AOSP build system and get this compiled along with AOSP build images or integrate the unsigned apk into build and get it signed along with build so that we can install this on Android device.

But compiling the applications along with AOSP build is very time consuming process so the improvement to this is to create platform key (platform.jks) and use it in Android Studio to sign the applications.

This post details how to create the platform key file which can be used in Android Studio to sign the applications.

1) Using android AOSP build platform.pk8 , we need to generate platform.key file as,

$ openssl pkcs8 -inform DER -nocrypt -in $ANDROID_ROOT/build/target/product/security/platform.pk8 -out platform.key

This will create a private key having “BEGIN PRIVATE KEY” and “END PRIVATE KEY” tag as,

$ file platform.key
platform.key: ASCII text

2) Using above platform.key, generate the platform.pem file as,

$ openssl pkcs12 -export -in $ANDROID_ROOT/build/target/product/security/platform.x509.pem -inkey platform.key -name platform -out platform.pem -password pass:password

Notice above the string used “password” , we need to use this later into build.gradle file.. You can change this as required. Above command, generate the platform.pem file as can be seen below,

$ file platform.pem
platform.pem: data

3) Using above platform.pem file, we can generate the final platform.keystore file as,

$ keytool -importkeystore -destkeystore platform.keystore -deststorepass password -srckeystore platform.pem -srcstoretype PKCS12 -srcstorepass password

Notice above the string used “password” along with storepass. we need to use this later into build.gradle file.. You can change this as required.

Now, with above command, we get the final platform key or “Java KeyStore” file as,

$ file platform.keystore
platform.keystore: Java KeyStore

Now, we need to copy this file along with Android Studio and use it in Android Studio Singing options, and same time modify build.gradle file as,

signingConfigs {
 release {
    storeFile     file('platform.keystore')
    storePassword 'password'
    keyAlias      'platform'
    keyPassword   'password'
 } 
}

Reference : https://stackoverflow.com/questions/51723768/how-to-sign-android-app-with-platform-keys-using-gradle

Leave a Comment