How to correctly re-compile an apk file?
Asked Answered
B

3

6

i was trying to inspect an .apk file for a project, so i decided to decompile it using APKtool using:

apktool d name.apk

I find what i wanted, changed it (i modified just a bunch of .json file and some .png, all in the /assets folder), but after re-building it with

apktool b name -o new.apk

I had some problems in installing the app on my device. Any suggestions?

It could be the signature of the .apk, according to other similar questions. But none of those explain the method to sign the .apk file in a correct way.

Bayard answered 24/2, 2021 at 16:24 Comment(0)
R
14

The following is for your reference


Compile, decompile and sign APK using apktool utility.

  1. Download latest apktool version.

  2. Download the batch file and aapt.exe.

  3. Create a folder anywhere in the PC and put all the apktool.jar, aapt.exe and the batch script in that folder.

  4. Open command prompt.

  5. Navigate to the folder where you placed apktool.jar, batch script and the aapt.exe.

  6. Now, you need to install the file using the " IF " command.

  7. Type the following command.

    apktool if name-of-the-app.apk

  8. For decompiling use the command "d". The "d" stands for decompile.

    apktool d name-of-the-app.apk

  9. After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mode's.

  10. To recompile the app use the following command " B ". The "b" simply means recompile.

    apktool b name-of-the-app-folder

  11. The final modded app will be in the "dist" folder located inside the original app folder created by apktool.

Signing the apk

  1. open a new command prompt and change into the sign-apk directory using cmd

  2. move the modified-unsigned apk into this folder

  3. then type the following command -

    java -jar signapk.jar certificate.pem key.pk8 path-of-the-folder-contaning-the-apk.apk path-of-the-new-signed-apk.apk

  4. Once compiled, the signed apk will be found in the same folder.

Remediosremedy answered 25/2, 2021 at 1:44 Comment(1)
where to find certificate.pem?Outsail
F
1

New compilations should use zipalign & apksigner tools from android-sdk build-tools.
BTW you can use keytool to create your keystore.
Or.. simply use the cross-platform buildapp command (pip install buildapp):
buildapp -d <sources_folder> -o <outout_apk>

Fredella answered 11/4, 2023 at 11:30 Comment(0)
I
0

https://liapp.lockincomp.com/blog/blog-Post/tech-apk-signature-scheme-v2-with-apksigner

https://developer.android.com/tools/apksigner

keytool -genkeypair -v -keystore keystore.jks -keyalg RSA -keysize 2048 -validity 3650 -alias mykey

this will create keystore.jks file

/home/$USER/DevTools/Android/build-tools/33.0.1/apksigner sign --ks keystore.jks zipalign_app2.apk

you will need android build tools and for android build tools [https://medium.com/@barcelos.ds/install-android-sdk-in-the-ubuntu-20-04-lts-without-android-studio-1b629924d6c5]

you will need java in your system [https://medium.com/@barcelos.ds/install-openjdk-11-lts-in-the-ubuntu-20-04-lts-2c06f17c990]

sorry i am in hurry so this are all resources i used

Intermeddle answered 17/10, 2023 at 3:49 Comment(1)
and after spending 5 days i am getting app not installedIntermeddle

© 2022 - 2024 — McMap. All rights reserved.