Apktool: APK crashes on (2.4.0, 2.3.4, 2.3.3, 2.3.2), works fine using 2.3.1

Created on 7 Mar 2019  路  10Comments  路  Source: iBotPeaches/Apktool

Information

  1. Apktool 2.4.0
  2. Windows (x64)
  3. APK from ApkMirror/Playstore/etc. (all produce the same issue)

Stacktrace/Logcat

E/MessageQueue-JNI(3648): Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI(3648): android.content.res.Resources$NotFoundException: File res/raw/voice_note_start.wav from drawable resource ID #0x7f0f000c
E/MessageQueue-JNI(3648):   at android.content.res.Resources.openRawResourceFd(Resources.java:1315)
E/MessageQueue-JNI(3648):   at android.media.SoundPool.load(SoundPool.java:245)

Steps to Reproduce

  1. apktool d (with apktool 2.4.0)
  2. apktool b (with apktool 2.4.0)
  3. sign, install the apk.
  4. Open the app and try to record a voice note.

_Notes_:

  • I tried building using apktool versions: 2.3.2, 2.3.3, 2.3.4. ALL produce the same crash
  • The strange thing is, using version 2.3.1 to build, the app works fine and doesn't crash.

Frameworks

Apktool default.

APK

If this APK can be freely shared, please upload/attach a link to it.
https://www.apkmirror.com/apk/whatsapp-inc/whatsapp/whatsapp-2-19-34-release/whatsapp-messenger-2-19-34-2-android-apk-download/

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? Yes
  2. If you are trying to install a modified apk, did you resign it? Yes
  3. Are you using the latest apktool version? Yes

Most helpful comment

UPDATE 1

100% confirmed, the crash is caused by this commit a8bdad628a58e65313521b809d8df60f3f86d40e.

I have built 2.4.1 (snapshot) with reverting the above commit, and the app APK no longer crashes!

You can do the tests yourself. (@B88B can you confirm the fix?)
apktool-cli-all-issue2036.zip

@iBotPeaches Any thoughts on why zipPackage() is causing this issue?

All 10 comments

This looks like an AAPT/AAPT2 similar to the https://github.com/iBotPeaches/Apktool/issues/2032 issue reported...

~Ibuprophen

@ibuprophen1 I've seen issue #2032 (which is related to the ids.xml). Mine is not similar.

I agree it might be AAPT related, because the APK is trying to load a .wav (raw) file using the drawable identifier!

Well git blaming myself all the way back to 2.3.1 will be impossible, so guess we have to treat this as a bug vs regression.

@iBotPeaches First of all, thank you for your time and efforts on apktool.

I'm just raising this issue as it's really strange and confused by how aapt can classify .wav file as a drawable.

IMO, I'm not sure if this is a bug vs regression; as this may affect many future apks with large /res folders.
So it might be worth looking at now before growing.

@B88B I can confirm this issue, it affects me too!

@iBotPeaches I spent hours looking into this issue and I found the cause:
It is this Androlib.java (line 698)

In commit a8bdad628a58e65313521b809d8df60f3f86d40e, you started using _zipPackage()_ to build the apk instead of _aaptPackage()_. And zipPackage() is somehow tampering with the resources in final APK
(perhaps it explains the smaller APK size?).

I did some tests by building Apktool 2.3.2 (from source code) by changing back to aaptPackage() instead of zipPackage(), and was able to fix the crash issue.

Proof-of-concept test (Try the following using 2.3.1 and 2.3.2+):

  1. apktool d file.apk
  2. apktool b file.apk

Results:

  • APK file packaged with 2.3.1 works fine!
  • APK file packaged with 2.3.2+ crashes on recording voice note (& is smaller in size)!

I am looking into this matter, and will update you with my progress :)

UPDATE 1

100% confirmed, the crash is caused by this commit a8bdad628a58e65313521b809d8df60f3f86d40e.

I have built 2.4.1 (snapshot) with reverting the above commit, and the app APK no longer crashes!

You can do the tests yourself. (@B88B can you confirm the fix?)
apktool-cli-all-issue2036.zip

@iBotPeaches Any thoughts on why zipPackage() is causing this issue?

@YoBasha I can confirm, it is fixed and everything working fine.
THANK YOU VERY MUCH, you're the man! I hope you can help provide a permanent solution for future apktool versions.

@YoBasha Reverting that commit returns aapt1 to the process during the build of applications, which if you are using an aapt2 build is not feasible. We cannot revert that, so need to identify why Apktool is not moving files to correct location.

UPDATE 2:

After spending countless hours testing, I think there is no problem in Apktool.

Important notes:

  1. Apktool 2.3.1 doesn't produce a 'doNotCompress' files list in apktool.yml.
  2. Apktool 2.4.0 produce a list of 'doNotCompress' files, to know which files to avoid compressing when building again.

My Theory:

  • This issue ONLY happens when: _decoding APK on Apktool 2.3.1_, and then _building it on Apktool 2.3.2-2.4.0._
    Why? Because Apktool 2.4.0 will compress all files - including the .wav - resulting in the app crash.

So @B88B , I guess there is no bug in Apktool 2.4.0. Next time just use 2.4.0 for the whole process (decode and build).

@iBotPeaches I think you can close this issue now, as it is just a inproper use of Apktool.

@iBotPeaches I think you can close this issue now, as it is just a inproper use of Apktool.

Sorry for delay. Thanks for triage. Closing.

Was this page helpful?
0 / 5 - 0 ratings