Apktool: Error parsing XML: not well-formed (invalid token)

Information

  1. Apktool Version: 2.2.1
  2. Operating System: Both Linux and Windows
  3. APK From: Playstore (https://play.google.com/store/apps/details?id=com.musixmatch.android.lyrify&hl=en)

Steps to Reproduce

  1. Download apk from (https://apkpure.com/musixmatch-lyrics-and-music/com.musixmatch.android.lyrify)
  2. Decompile apk using apktool d music.apk -o output (You will notice non-ascii characters in decompiled files both Smali and XML files which probably the reason recompiling fails)
  3. Try to recompile the output using apktool b output, it would fail leaving the following errors
I: Using Apktool 2.2.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /output/res/layout/abc_action_mode_bar.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/abc_action_mode_close_item_material.xml:2: error: No resource identifier found for attribute 'srcCompat' in package 'android'
W:
W: /output/res/layout/abc_dialog_title_material.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v17/abc_dialog_title_material.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/abc_screen_simple.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/abc_screen_simple_overlay_action_mode.xml:5: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/abc_screen_toolbar.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v21/abc_screen_toolbar.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/com_facebook_device_auth_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v16/com_facebook_device_auth_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v17/com_facebook_device_auth_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/com_facebook_smart_device_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v16/com_facebook_smart_device_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout-v17/com_facebook_smart_device_dialog_fragment.xml:8: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/design_bottom_navigation_item.xml:5: error: Error parsing XML: not well-formed (invalid token)
W:
W: /output/res/layout/design_bottom_sheet_dialog.xml:5: error: No resource identifier found for attribute 'layout_behavior' in package 'android'
W:
W: /output/res/layout-v16/design_bottom_sheet_dialog.xml:5: error: No resource identifier found for attribute 'layout_behavior' in package 'android'
W:
W: /output/res/layout/design_text_input_password_icon.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
.....................

APK

Musixmatch Lyrics (https://play.google.com/store/apps/details?id=com.musixmatch.android.lyrify&hl=en)

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? -No
  3. Are you using the latest apktool version? -Yes

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 1
  • Comments: 25 (6 by maintainers)

Most upvoted comments

Happens for me with resource xml with $ in tag name, e.g.

<?xml version="1.0" encoding="utf-8"?>
<o.RatingCompat$1 id="@id/expanded_menu" layout_width="?panelMenuListWidth" layout_height="wrap_content"
  xmlns:android="http://schemas.android.com/apk/res/android" />

Is the problem not resolved yet? I am having the same problem now.

Ticket looks open and unresolved to me. So no isn’t resolved.

2020 update. Still an issue.

➜  1407 apktool b 1407 --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 sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/animator/2130837504.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/animator/2130837504.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/animator/2130837509.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/animator/2130837509.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099651.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099651.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099666.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099666.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099667.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099667.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099668.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099668.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099669.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099669.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099670.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099670.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099671.xml:4: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099671.xml: error: file failed to compile.
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099896.xml:5: error: not well-formed (invalid token).
W: /home/ibotpeaches/Downloads/Apktool/1407/1407/res/color/2131099896.xml: error: file failed to compile.
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_8728117719843997481760221012075490107.tmp, compile, --dir, /home/ibotpeaches/Downloads/Apktool/1407/1407/res, --legacy, -o, /home/ibotpeaches/Downloads/Apktool/1407/1407/build/resources.zip]
➜  1407 

@iBotPeaches couldn’t you - optionally - pass some params to the XML tool so that it ignores these errors? The XML format errors come from the source APK so they’re probably OK with those errors.

@iBotPeaches would mind pointing me to the code that throws error: Error parsing XML: not well-formed (invalid token)?

I want to see if I can figure out what’s going on here, but my Java-fu is minimal. If it is indeed libexpat issue, it should be possible to patch it and include with your files, as it has no other dependencies.

That is in aapt/aapt2 so you won’t find it. You’ll want to check

@iBotPeaches does this have to do with a bug in libexpat as mentioned above? And if so, would you consider bundling a patched version of libexpat with your packages?

I have not done enough research to know if that is true. So unsure.

FWIW, this seems to come down to a bug in libexpat which doesn’t allow the proper character set for names. When a XML resources refers to proguarded names, it has good chances to crash. See https://github.com/libexpat/libexpat/issues/171