Which process you want to follow, there are two ways available:-
- Manage the key and keystore by self or
- Using google app signing.(Which later on provide the support for retrieve key even when you loses it).
Let's talk about the First one which is used most the time and easy.
Steps:-
- Create Keystore file and save password, alias and alias password on some safe place.
- Keep that keystore file on the same place where you kept the file with above credentials.
- Now go to build->Generate Signed APK-> Select keystore file you have just created, provide all the required credentials like:- password, alias, alias password.
- Android studio generate the Signed APK for you and you can upload the same on playstore.
- When next time you again generate a APK you need to follow only step 3 and step 4, as you keystore file is going to use same as you have used earlier, because you are pushing an app update. And when you want to update a app the APK should sign with the same keystore or you can say same SHA certificate.
If you want to do whole process by cammand then you can add the buildType in app.gradle file, which is more better and appropriate way.
To add buildType configuration please see the gradle code:-
android{
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
storeFile file("path for release.keystore")
storePassword keystore_password
keyAlias keystore_alias
keyPassword keystore_alias_password
}
}
}
In above configuration you need to provide file path of release keystore file in storeFile
tag, and also need to provide the credentials in storePassword, keyAlias and keyPassword as mentioned.
After adding above configuration now you can generate signed apk by simple gradlew command:- ./gradlew clean assembleRelease
If you want to go with second method Signing with google app key details are available here if you getting any problem at any step please mention that step so I can solve the problem.
For generating the Upload key first you need to do this:-
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
then sign the apk using :
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keys
You can also use github lib to automate whole process from here.
Or you can refer here for more details.