As an android developer, we faced many challenges to build and deploy the app to the market. Here I am going to discuss one of the challenges is signed the APK from the newly created Keystore or exiting Keystore from the android studio.
As we know the android studio having two different build types named debug and release. Generally, when we run the application in debug mode than by default the android studio signed the APK from debugging Keystore. We can find the debug Keystore in the corresponding home directory of the system which is used to sign the APK by the android studio. The default name for the Keystore is debug.keystore
that has a Keystore password android
.
In debug mode, we do not face any problem because it handles by an android studio internally. Generally, We faced the challenge in release mode which we are going to discuss in this article to sign the release APK from exiting keyStore by using the android studio. Let’s discuss all the steps for signing the APK in release mode.
In the very first step, we need to generate the Keystore to sign the APK from the android studio. If you have already generated the Keystore then we can use the exiting Keystore else we can create the new one from the android studio.
Go to the top sidebar of the android studio, and click on build and select to Generate the Signed the APK, it will open a pop-up window to ask for sign the APK from the exiting Keystore or create the new key store. Here is a screenshot for creating the new Keystore.
Here we need to fill all the needed information with alias key and password if it is already created which needs to remember while generating the signed APK. But here I am going to use this key and password inside the Keystore.properties file to avoid remembering the stuff. After completing all the information it will generate the .jks file inside the chosen directory.
storePassword=android keyPassword=android keyAlias=androidalias storeFile=keystore/test_sign.jks
Please paste the created .jks file inside the Keystore folder. Here I had chosen the alias key is “androidalias” and password is “android”. It’s up to you to decide the key alias and password. I need to create the Keystore folder inside the app of your project and paste the created Keystore (.jks) file.
From the official document:
Once you entered the required information, it will generate the code inside the build.gradle file.
android { signingConfigs { config { keyAlias "here aliase" keyPassword "here aliase" storeFile "here file" storePassword "here password" } } ..... }
Note:
It is not best practice to put the passwords as hardcoded constants in the build file. A better approach would be to put them in a separate
file that is not part of the Version Control System (
VCS
).
We can write all the secret information like alias and password into the Keystore.properties file as I shared above of this article and give access to this file to build.gradle to read information.
// Create a variable called keystorePropertiesFile, and initialize it to your // keystore.properties file, in the rootProject folder. def keystorePropertiesFile = rootProject.file("keystore.properties") // Initialize a new Properties() object called keystoreProperties. def keystoreProperties = new Properties() // Load your keystore.properties file into the keystoreProperties object. keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { signingConfigs { config { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } buildTypes { debug { /// set for debug } release { minifyEnabled true signingConfig signingConfigs.config } } }
Now we need to just select the release from build variant and build the APK. It will take a moment to generate the release APK to the corresponding directory.
That’s all.
Wrapping
Now we have a good understanding of signing the APK in release mode.
If you are wondering to learn Android then Please learn from Android category and wondering to learn Kotlin then Kotlin Category will help you. If you want to learn all the python article, then learn from the python category.
Happy Coding 🙂
I am a very enthusiastic Android developer to build solid Android apps. I have a keen interest in developing for Android and have published apps to the Google Play Store. I always open to learning new technologies. For any help drop us a line anytime at contact@mobologicplus.com
Hi everyone, In this article, we are going to learn how to hide the production… Read More
Hello everyone, Today in this article, we are going to learn about localisation to support… Read More
Hello everyone, In this article, we are going to learn something to handle the callback… Read More
In this article, we are learning about the run time permissions for request permission launchers.… Read More
Hello everyone. In my last tutorial, we learned about the Jetpack Compose introduction and about applying the… Read More
Hello everyone, In this article, we are going to learn about the Jetpack Compose with… Read More