Generating Signed APK

1.In order to generate signed apk in android you have to type the following command in this directory C:\Program Files\Java\jdkx.x.x_x\bin
(remember run command prompt as an administrator mode)
$ keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
This command prompts ask you for passwords for the keystore and key and for 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, so remember to take note of the alias.
2 copy the generate file ie my-release-key.keystore under android/app folder
 Then edit the file  ~/.gradle/gradle.properties and add the following (replace **** with the correct keystore password, alias and key password)
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=****
MYAPP_RELEASE_KEY_PASSWORD=****
3 Edit build.gradle under app(app/build.gradle)
remember if you accidently edit the outside build.gradle file you will get an error like this
Android Build Exception - Could not find method android() blah blah .......
the sections with signingConfigs only may need to be added after defaultConfig bracket closed then 
again add below code under release section.
...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...
4 Then run the command cd android && ./gradlew assembleRelease.
5 The signed apk will generate under android\app\build\outputs\apk\release.

1 Comments

james shrestha

October 31, 2019 11:53 AM

This article really help me alot. Thank You

Leave a reply

your email address will not be published. required fields are marked *

Name *