Apktool: Exception in thread "main" java.lang.NullPointerException

Created on 3 Aug 2019  Â·  14Comments  Â·  Source: iBotPeaches/Apktool

Information

  1. Apktool Version (apktool -version) - 2.4.0 & 2.4.1-75e4c6-SNAPSHOT
  2. Operating System (Mac, Linux, Windows) - Linux
  3. APK From? (Playstore, ROM, Other) - Playstore

Stacktrace/Logcat

$ java -jar apktool_2.4.0.jar d JioSaavn_6.4.1.apk
I: Using Apktool 2.4.0 on JioSaavn_6.4.1.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/surendra/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
Exception in thread "main" java.lang.NullPointerException
    at brut.androlib.res.data.value.ResEnumAttr.serializeBody(ResEnumAttr.java:56)
    at brut.androlib.res.data.value.ResAttr.serializeToResValuesXml(ResAttr.java:64)
    at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:704)
    at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:263)
    at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
    at brut.androlib.ApkDecoder.decode(ApkDecoder.java:124)
    at brut.apktool.Main.cmdDecode(Main.java:167)
    at brut.apktool.Main.main(Main.java:76)
Process exited with code 1.

$ java -jar Apktool/brut.apktool/apktool-cli/build/libs/apktool-cli-all.jar d JioSaavn_6.4.1.apk
I: Using Apktool 2.4.1-75e4c6-SNAPSHOT on JioSaavn_6.4.1.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/surendra/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
Exception in thread "main" java.lang.NullPointerException
    at brut.androlib.res.data.value.ResEnumAttr.serializeBody(ResEnumAttr.java:56)
    at brut.androlib.res.data.value.ResAttr.serializeToResValuesXml(ResAttr.java:64)
    at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:703)
    at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:260)
    at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:131)
    at brut.androlib.ApkDecoder.decode(ApkDecoder.java:124)
    at brut.apktool.Main.cmdDecode(Main.java:170)
    at brut.apktool.Main.main(Main.java:76)
Process exited with code 1.

Steps to Reproduce

  1. $ java -jar apktool_2.4.0.jar d JioSaavn_6.4.1.apk

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files
(.apks that live in /system/framework or /system/priv-app) NA

APK

If this APK can be freely shared, please upload/attach a link to it.
JioSaavn

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? NA
  3. Are you using the latest apktool version? YES
Bug

Most helpful comment

Confirmed. I can replicate the issue. Thanks for following issue template and attaching sample application.

All 14 comments

Confirmed. I can replicate the issue. Thanks for following issue template and attaching sample application.

I'm getting the same error with https://play.google.com/store/apps/details?id=at.rsg.pfp , if more samples are useful for this bug.

All the apk files which are facing this issue have something common ie. all the resource files are not in the /res dir but in the root dir and have weirdly encoded names.

Apk analyzer from Android Studio is failing to parse the AndroidManifest.xml correctly of the apk. It's reporting with unexpected tokens error.

@iBotPeaches I tried decoding the JioSaavn apk with JEB and I guess I got the issue. It uses a clever renaming for resources dirs and files with only white spaces or special characters in the name. Here are the decompilation logs.

Same problem with this app: https://apkcombo.com/weapon-heroes-infinity-forge-idle-rpg/com.gamepub.mc.g/

Exception in thread "main" java.lang.NullPointerException
    at java.io.Writer.write(Unknown Source)
    at org.xmlpull.renamed.MXSerializer.attribute(MXSerializer.java:631)
    at org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate.attribute(XmlSerializerDelegate.java:106)
    at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.writeStartTag(StaticXmlSerializerWrapper.java:267)
    at org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper.event(StaticXmlSerializerWrapper.java:211)
    at brut.androlib.res.decoder.XmlPullStreamDecoder$1.event(XmlPullStreamDecoder.java:84)
    at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:142)
    at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:154)
    at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:162)
    at brut.androlib.res.AndrolibResources.decodeManifestWithResources(AndrolibResources.java:204)
    at brut.androlib.Androlib.decodeManifestWithResources(Androlib.java:134)
    at brut.androlib.ApkDecoder.decode(ApkDecoder.java:122)
    at brut.apktool.Main.cmdDecode(Main.java:170)
    at brut.apktool.Main.main(Main.java:76)

I am having the same problem with Weapon Heroes. With 2.4.1 and a build from master.

This will be fixed in v2.5.0

➜  2146 apktool d com.jio.media.jiobeats_215_apps.evozi.com.apk -f
I: Using Apktool 2.4.2-f545c2-SNAPSHOT on com.jio.media.jiobeats_215_apps.evozi.com.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/ibotpeaches/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
➜  2146 

Closing.

@iBotPeaches Thanks but please check the apktool.yml file after decoding the JioSaavn app. It's malformed and contains some weird characters. I think those need to be sanitized first.

Decoded successfully..

$ java -jar ./brut.apktool/apktool-cli/build/libs/apktool-cli-all.jar d ~/Downloads/jiosaavn-music-radio-–-jiotunes-podcasts-songs_7.3.1.apk 
I: Using Apktool 2.4.2-734793-SNAPSHOT on jiosaavn-music-radio-–-jiotunes-podcasts-songs_7.3.1.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/surendra/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Baksmaling classes3.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory

Tried to build again...

$ java -jar ./brut.apktool/apktool-cli/build/libs/apktool-cli-all.jar b ~/Downloads/jiosaavn-music-radio-–-jiotunes-podcasts-songs_7.3.1.apk -f
I: Using Apktool 2.4.2-734793-SNAPSHOT
brut.directory.PathNotExist: apktool.yml

Output apktool.yml

Didn't have that issue. It didn't build, but I'll chuck that up to a more strict aapt2.

➜  2146 apktool b com.jio.media.jiobeats_215_apps.evozi.com --use-aapt2
I: Using Apktool 2.4.2-f545c2-SNAPSHOT
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-anydpi-v26/mipmaps.xml:3: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-anydpi-v26/mipmaps.xml:4: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-anydpi-v26/mipmaps.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-hdpi/mipmaps.xml:3: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-hdpi/mipmaps.xml:4: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-hdpi/mipmaps.xml:5: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-hdpi/mipmaps.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-mdpi/mipmaps.xml:3: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-mdpi/mipmaps.xml:4: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-mdpi/mipmaps.xml:5: error: invalid value for type 'mipmap'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-mdpi/mipmaps.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small-v21/layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small-v21/layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small-v21/layouts.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small/layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small/layouts.xml:4: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small/layouts.xml:5: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small/layouts.xml:6: error: invalid value for type 'layout'. Expected a reference.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-small/layouts.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res/values-sw600dp/layouts.xml:3: error: invalid value for type 'layout'. Expected a reference.
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_1525413125471613972157943034179406338.tmp, compile, --dir, /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/res, --legacy, -o, /home/ibotpeaches/Downloads/Apktool/2146/com.jio.media.jiobeats_215_apps.evozi.com/build/resources.zip]
➜  2146 

@iBotPeaches my bad. I was passing the wrong dir. But yes, it fails to build with both aapt1 and aapt2. Should I open another issue for that?

@iBotPeaches my bad. I was passing the wrong dir. But yes, it fails to build with both aapt1 and aapt2. Should I open another issue for that?

I would investigate those first, if those are warnings because aapt2 is more restrictive then probably not. If it appears that it should be working, then sure. We should investigate.

Was this page helpful?
0 / 5 - 0 ratings