Tuesday, November 29, 2016

Signing your modified android apk

While installing modified apk,I saw an error stating INSTALL_PARSE_FAILED_NO_CERTIFICATES.
After some research I found the solution for same.

Pre-install:
1) Install Android studio at https://developer.android.com/studio/index.html While Installation, it will ask path for android sdk, configure that path as per your need.
2) In my case it was like C:\Users\anurag\AppData\Local\Android\sdk1.
3) We are mainly interested in adb.exe which is present inside platform-tools, so for me the desired adb.exe path was C:\Users\anjain\AppData\Local\Android\sdk1\platform-tools\adb.exe
4) Add adb.exe in your system environment variables so that you can access adb from command prompt directly.


Problem:
1) Suppose you modified an apk named myapk.apk
2) You try to install the apk using
 adb install myapk.apk  
3) This returns an error Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
4) This happens because your apk need to be signed again after you modified your apk.

How to sign your jar:

1) Copy the debug.keystore from C:\Users\<YOUR_USERNAME>\.android and place it in the same directory where your modified apk is present.
2) Change extension of your apk file to zip and open it using software like winzip and winrar. (For example your apk was myapk.apk then rename to myapk.zip)
3) Move to META-INF directory inside the myapk.zip.
4) Delete the 2 files with extension SF and RSA. For my case it was CERT.SF & CERT.RSA. For same reason I used CERT in step 7 & 8
5) Close winzip and rename the extension again to apk (For example your apk was myapk.zip then rename to myapk.apk)
6) Open command prompt and point to the directory where your modified apk is present
7) Enter below command: (Password: android)
 keytool -genkey -v -keystore debug.keystore -alias CERT -keyalg RSA -keysize 2048 -validity 20000  
8) Enter below command:
 jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore debug.keystore <Your apk filename with extension> CERT  
9) Verify if jar was signed properly by hitting below command:
 jarsigner -verify <Your apk filename with extension>  
10) If you dont see any error then everything is fine and you can now simply use below command to install in your smartphone
 adb install <Your apk filename with extension>  

Reference:
https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm
https://developer.android.com/studio/index.html
https://dzone.com/articles/android-solution-install-parse-1

Hope it helps :)

No comments:

Post a Comment