REAndroid / APKEditor

Powerful android apk editor - aapt/aapt2 independent
Apache License 2.0
847 stars 127 forks source link

Apk fails to run after no changes made #12

Closed dejanberic closed 1 year ago

dejanberic commented 1 year ago

I have tried to use your tool on Starbucks app, you can download it here: https://apkcombo.com/starbucks/com.starbucks.mobilecard/

I have tried to just decompile and build, no changes applied. Build fails in this case:

00.019 I: [BUILD] Scanning JSON directory ... 00.063 I: [BUILD] Writing apk... Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.reandroid.arsc.chunk.xml.ResXmlStartNamespace.getUriReference()" because "ns" is null at com.reandroid.arsc.chunk.xml.ResXmlAttribute.fromJson(ResXmlAttribute.java:336) at com.reandroid.arsc.array.ResXmlAttributeArray.fromJson(ResXmlAttributeArray.java:139) at com.reandroid.arsc.chunk.xml.ResXmlElement.fromJson(ResXmlElement.java:785) at com.reandroid.arsc.chunk.xml.ResXmlElement.fromJson(ResXmlElement.java:798) at com.reandroid.arsc.chunk.xml.ResXmlDocument.fromJson(ResXmlDocument.java:224) at com.reandroid.apk.JsonXmlInputSource.getResXmlBlock(JsonXmlInputSource.java:53) at com.reandroid.apk.JsonXmlInputSource.write(JsonXmlInputSource.java:35) at com.reandroid.archive.ZipSerializer.write(ZipSerializer.java:77) at com.reandroid.archive.ZipSerializer.writeZip(ZipSerializer.java:67) at com.reandroid.archive.ZipSerializer.writeZip(ZipSerializer.java:44) at com.reandroid.apk.ApkModule.writeApk(ApkModule.java:164) at com.reandroid.apk.ApkModule.writeApk(ApkModule.java:139) at com.reandroid.apkeditor.compile.Builder.buildJson(Builder.java:62) at com.reandroid.apkeditor.compile.Builder.run(Builder.java:44) at com.reandroid.apkeditor.compile.Builder.execute(Builder.java:144) at com.reandroid.apkeditor.Main.execute(Main.java:60) at com.reandroid.apkeditor.Main.main(Main.java:38)

I have also tried to apply x command, to refactor the resource names. It made an apk file, and I have signed it, successfully installed it, but the app crashes on the very start.

Can you help me with this issue?

REAndroid commented 1 year ago

Fixed with this commit and your apk also points out serious issue on reading spec and type which is fixed on this commit

You can also download updated jar from here

dejanberic commented 1 year ago

Thanks for the update. Now the APKEditor does not crash but the Starbucks app does not start after decompile/recompile nor it starts after just refactoring with APKEditor. I have found that Starbucks v6.14 does start after refactor. So I am not sure what are the differences here and why it wont start with the latest version 6.42. I am using NoxPlayer, with android 9 to install the Starbucks app.

REAndroid commented 1 year ago

I have tested with v6.42, it works fine, run refactor first -> decompile -> build

Tested with android-9

dejanberic commented 1 year ago

I have run refactor -> decompile -> build on v6.42. The app is still not starting on NoxPlayer. I am on Windows 10. Are you using a different OS and a different Android VM? Can you upload somewhere your APK that works so I can compare it with mine?

REAndroid commented 1 year ago

Check this commit Try the latest update APKEditor-1.1.7-UPDATE-5

dejanberic commented 1 year ago

I have tried to use that latest UPDATE-5 but I get the same results, the APK is installed but crashes on startup. I have used this windows CMD script:

java -jar APKEditor.jar x -i files/%1.apk java -jar APKEditor.jar d -i files/%1_refactored.apk java -jar APKEditor.jar b -i files/%1_refactored_decompile_json rmdir /S /Q "./files/%1_refactored_decompile_json" cd files del /Q "%1_refactored_decompile_json_out.apk.tmp" cd.. IF EXIST files/%1_refactored_decompile_json_out.apk zipalign.exe -f -v 4 files/%1_refactored_decompile_json_out.apk signed/%1_refactored_decompile_json_out.apk IF EXIST files/%1_refactored_decompile_json_out.apk "C:\Users\Dejan\AppData\Local\Android\Sdk\build-tools\33.0.0\apksigner.bat" sign --ks my.keystore files/%1_refactored_decompile_json_out.apk

APKEditor.jar is located in APKTool folder, the Starbucks_6.42.apk is located in APKTool/files folder.

I have also tried to run the script without the zipalign, but the result is the same, app crashes.

This is the output when I run the script without the zipalign:

D:\Install\Programming\APK Decompile\APktool>java -jar APKEditor.jar x -i files/Starbucks_6.42.apk 00.000 I: [REFACTOR] Refactoring ... Input: files\Starbucks_6.42.apk Output: files\Starbucks_6.42_refactored.apk

00.018 I: [REFACTOR] Loading apk: files\Starbucks_6.42.apk 00.323 I: [REFACTOR] Initializing android framework ... 00.323 I: [REFACTOR] Loading android framework for version: 33 00.471 I: [REFACTOR] Initialized framework: android-33 00.471 I: [REFACTOR] Auto refactoring ... 01.105 I: [REFACTOR] Auto renamed entries: 9414 01.256 I: [REFACTOR] Writing apk ... 06.845 [REFACTOR] Writing: AndroidManifest.xml 07.125 I: [REFACTOR] Zip align ... 07.211 I: [REFACTOR] Saved to: files\Starbucks_6.42_refactored.apk 07.211 I: [REFACTOR] Done

D:\Install\Programming\APK Decompile\APktool>java -jar APKEditor.jar d -i files/Starbucks_6.42_refactored.apk 00.000 I: [DECOMPILE] Decompiling ... Input: files\Starbucks_6.42_refactored.apk Output: files\Starbucks_6.42_refactored_decompile_json Type: json Split: false

00.017 I: [DECOMPILE] Loading ... 00.312 I: [DECOMPILE] Initializing android framework ... 00.312 I: [DECOMPILE] Loading android framework for version: 33 00.454 I: [DECOMPILE] Initialized framework: android-33 00.455 I: [DECOMPILE] Decompiling to JSON ... 00.456 I: [DECOMPILE] [SANITIZE]: Sanitizing paths ... 00.476 I: [DECOMPILE] [SANITIZE]: DONE = 2597 02.460 I: [DECOMPILE] Saved to: files\Starbucks_6.42_refactored_decompile_json 02.460 I: [DECOMPILE] Done

D:\Install\Programming\APK Decompile\APktool>java -jar APKEditor.jar b -i files/Starbucks_6.42_refactored_decompile_json

00.000 I: [BUILD] Building ... Input: files\Starbucks_6.42_refactored_decompile_json\base Output: files\Starbucks_6.42_refactored_decompile_json_out.apk

00.017 I: [BUILD] Scanning JSON directory ... 00.852 I: [BUILD] Writing apk... 09.522 [BUILD] Writing:AndroidManifest.xml 09.798 I: [BUILD] Zip align ... 09.912 I: [BUILD] Built to: files\Starbucks_6.42_refactored_decompile_json_out.apk 09.912 I: [BUILD] Done

D:\Install\Programming\APK Decompile\APktool>rmdir /S /Q "./files/Starbucks_6.42_refactored_decompile_json"

D:\Install\Programming\APK Decompile\APktool>cd files

D:\Install\Programming\APK Decompile\APktool\files>del /Q "Starbucks_6.42_refactored_decompile_json_out.apk.tmp" Could Not Find D:\Install\Programming\APK Decompile\APktool\files\Starbucks_6.42_refactored_decompile_json_out.apk.tmp

D:\Install\Programming\APK Decompile\APktool\files>cd..

D:\Install\Programming\APK Decompile\APktool>IF EXIST files/Starbucks_6.42_refactored_decompile_json_out.apk "C:\Users\Dejan\AppData\Local\Android\Sdk\build-tools\33.0.0\apksigner.bat" sign --ks my.keystore files/Starbucks_6.42_refactored_decompile_json_out.apk Keystore password for signer #1: D:\Install\Programming\APK Decompile\APktool>

REAndroid commented 1 year ago

Try decompile/compile without REFACTOR

1) APKEditor.jar d -i file.apk -o file_json 2) APKEditor.jar b -i file_json -o file_out.apk

Here is my decompile-compile starbuks

OS: Linux Tested on android API 28 real device

dejanberic commented 1 year ago

I have tried to decompile and build, without the refactor step. It fails to run. I noticed that your APK is 3 mb bigger than mine. I guess not all files were included because of the windows OS.

Here is mine APK: starbucks

I also noticed that your APK does not run on Nox Player, never tried it on a real device though.

REAndroid commented 1 year ago

@dejanberic Check the latest update : 1.2.9