Labels

Saturday 8 July 2017

[Android] Create a signed apk file

After spending a day trying to create a signed apk file from Android Studio but not successful. Finally I found the solution and it's not depending on Android studio.



These are step by step I do in Ubuntu 16.04 LTS
Step 1: Create keystore using keytool from JDK.
- Navigate to $JDK$/bin directory
- Execute command:
./keytool -genkey -v -keystore vocabulary_note.keystore -alias vocabulary_note -keyalg RSA -keysize 2048 -validity 10000




Explanation:
./keytool : execute keytool program
vocabulary_note.keystore: name of keystore, you can choose any name
vocabulary_note: alias of keystore, you can choose any name.
Enter password and complete  other steps.
Step 2: Generate unsigned apk file.
Open Android studio:
Run -> Edit configurations ...



Create a new Gradle task with following information:
Name: unsignApp
Gradle project: choose your project module
Tasks: assemble

In Run menu, select the configuration you've just created.

After running it you will see file unsigned apk file in your $android_studio_path$/$app_name$

Change the name to whatever you want and move it to keytool folder

For instance I change it name to vocabulary_note.apk

The keystore, unsigned apk, keytool, jarsigner files should in same folder.
 
Step 3: Create signed apk file.
Execute command:

./jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore vocabulary_note.keystore vocabulary_note.apk vocabulary_note

Explanation:

./jarsigner: run jarsigner program to create signed apk file from unsigned apk.
vocabulary_note.keystore: name of keystore, you can choose any name
vocabulary_note: alias of keystore, you can choose any name.
P/S
When using another third party modules, maybe you would face with another issue:




Just add these command to the proguard-rules.pro file with the appropriate class you don't want Android studio warn you.
-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
    native <methods>;
}




Hope it help !
That's it ^_^

No comments:

Post a Comment