Skip to content

APK decode rebuild zipalign

Dark Cowling edited this page Jan 19, 2023 · 4 revisions

Pre-requisite

Current as of 4 Jan '23

% java -version
java version "1.8.0_xxx"

You can install the command line tools here - https://developer.android.com/studio#command-tools
Or if you simply want apktool only - https://ibotpeaches.github.io/Apktool/install/

APK-jutsu

	[1] Decode the APK
	$ apktool d target.apk
	
	[2] Make changes and then rebuild back the APK
	$ apktool b folder -o TARGET.apk

[*] If you use apksigner, zipalign must only be performed before the APK file has been signed. If you sign your APK using apksigner and make further changes to the APK, its signature is invalidated.

	[3] Zipalign to optimise the Application
	$ zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
	
	[4] Use your own private key to sign the APK. 
	$ apksigner sign --ks my-release-key.jks --out my-app-release.apk my-app-unsigned-aligned.apk

[*] If you use jarsigner, zipalign must only be performed after the APK file has been signed.

	[3] Use your own private key to sign the APK. 
	$ jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android -digestalg SHA1 -sigalg MD5withRSA TARGET.apk androiddebugkey
	
	[4] Zipalign to optimise the Application
        $ zipalign -v -p 4 TARGET_signed.apk output.apk
Clone this wiki locally