Reputation: 85
So I wanted to replace one file in an application, and the way I did it is apktool d CATGAME.apk
, which decompiles the .apk.
Then I replaced the one file I need, and do apktool b CATGAME
to compile it. Then I zip align the file by running mv CATGAME.apk CATGAME-prealigned.apk; zipalign -v 4 CATGAME-prealigned.apk CATGAME.apk
After which, I do apksigner sign --ks ../ks.jks --v2-signing-enabled true --v3-signing-enabled true --min-sdk-version 29 CATGAME.apk
(ks.jks in the parent directory is they keystore)
And to verify I run apksigner verify CATGAME.apk
but the output is Exception in thread "main" com.android.apksig.apk.ApkFormatException: Missing AndroidManifest.xml at com.android.apksig.ApkSigner.getAndroidManifestFromApk(ApkSigner.java:970) at com.android.apksig.ApkVerifier.getAndroidManifestFromApk(ApkVerifier.java:1225) at com.android.apksig.ApkVerifier.verifyAndGetMinSdkVersion(ApkVerifier.java:640) at com.android.apksig.ApkVerifier.verify(ApkVerifier.java:196) at com.android.apksig.ApkVerifier.verify(ApkVerifier.java:164) at com.android.apksigner.ApkSignerTool.verify(ApkSignerTool.java:587) at com.android.apksigner.ApkSignerTool.main(ApkSignerTool.java:95)
After extracting CATGAME.apk I see that now it became two folders META-INF
and CATGAME
META-INF
contains ALIAS_NA.RSA
, ALIAS_NA.SF
and MANIFEST.MF
, while CATGAME
contains normal things that would be in a normal apk.
I'm trying to make a tool to automate the process of replacing that file so a GUI tool probably won't work.
UPDATE: You just have to add --append-signature, it took me too long to find out
Upvotes: 1
Views: 136
Reputation: 85
The solution was easy as adding --append-signature Sorry for wasting your time, I don't know how I didn't think of that
Upvotes: 0
Reputation: 66
After extracting CATGAME.apk I see that now it became two folders META-INF and CATGAME
Sounds like apk is corrupted. AndroidManifest.xml
, res/
& smali
directories are suppose to be in root of the apk, along with that META-INF
folder you mentioned. I guess the commands you used were incorrect (probably zipalign one is wrong)
For reference, try using these commands. They work in my case.
zipalign -p -f -v 4 CATGAME-prealigned.apk CATGAME-zipaligned.apk
apksigner sign --ks Your.keystore --in CATGAME-zipaligned.apk --out CATGAME.apk --v4-signing-enabled true
The alternative version incase keystore is password protected
apksigner sign --in CATGAME-zipaligned.apk --out CATGAME.apk --v4-signing-enabled true --ks YourKey.jks --ks-key-alias yourKeyAlias --ks-pass pass:yourPassword
Reference: https://developer.android.com/tools/apksigner
https://developer.android.com/tools/zipalign
Upvotes: 1