Monday, March 9, 2015

apktool usage: Decompile and Compile APK (in mac)

A. Installation:
1. Install Apktool

B. Process to Decompile APK(Android Package):
1. Open terminal and cd to apktool directory
2. $./apktool d <../../pathToMyAPK> 



3. Command generates a folder with all app resources and smali files

4. Now go to smali folder and you can make changes to the behavior of the app.

-->After you made changes to the app, you have to compile the source and then signed your app to work in a device(steps below)


C. Process to Compile APK(Android Package):

1. Open terminal and cd to apktool directory
2. $./apktool b <../../pathToMyAPK>
3. New apk is generated in  ./tool/out_decompile/dist/NewAPP.apk
->Now we need to sign the apk to be able to port to device.

D. Sign APK:
1. Generate release key using below command.
$keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
2. Enter password for key.

>creates key: /Users/android/my-release-key.keystore

2. Generate new apk(done in above step C. 2).
3. Sing your app
$jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore /Users/android/Desktop/tools/apktool/tool/compile_apk/myAPK-1.apk alias_name
4. Done. Signs apk, saved in the same location.
5. Install apk to device: $adb install /Users/android/Desktop/tools/apktool/tool/compile_apk/myAPK-1.apk   

Reference:
https://www.youtube.com/watch?v=XbvyqpnP1-E
https://code.google.com/p/android-apktool/downloads/list
Signing apk manually: 
http://developer.android.com/tools/publishing/app-signing.html