Apktool icon indicating copy to clipboard operation
Apktool copied to clipboard

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

Open aboodnour7 opened this issue 8 years ago • 33 comments

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

aboodnour7 avatar Jan 09 '17 21:01 aboodnour7

Thought I had fixed this in 2.2.2, but doesn't appear to be so. I need to patch the XMLNode class.

iBotPeaches avatar Jan 12 '17 12:01 iBotPeaches

I've come across another APK that's suffering from this issue:

Information

Apktool Version: 2.2.2 Operating System: Both Linux and Mac APK From: https://forum.xda-developers.com/android/apps-games/ps4-remote-play-android-thread-t3068225

Steps to Reproduce

$ apktool d RemotePlayPortV5.1_ITB.apk
...
$ apktool b RemotePlayPortV5.1_ITB

I: Using Apktool 2.2.2 on RemotePlayPortV5.1_ITB.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /root/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
root@99033f046f3d:/usr/src/apk# apktool b RemotePlayPortV5.1_ITB
I: Using Apktool 2.2.2
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog_game2_confirm.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog_game_confirm.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:477)
	at brut.androlib.Androlib.buildResources(Androlib.java:411)
	at brut.androlib.Androlib.build(Androlib.java:310)
	at brut.androlib.Androlib.build(Androlib.java:263)
	at brut.apktool.Main.cmdBuild(Main.java:227)
	at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:440)
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:463)
	... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.util.OS.exec(OS.java:95)
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:434)
	... 6 more

Example invalid .xml:

<?xml version="1.0" encoding="utf-8"?>
<o.ﺗ android:layout_gravity="center" android:orientation="vertical" android:background="@drawable/companionutil_drawable_alert_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" landscape_marginLeft="33dp" landscape_marginRight="33dp" portrait_marginLeft="11dp" portrait_marginRight="11dp"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <com.playstation.companionutil.CompanionUtilAdjustTextView android:textSize="16.0dip" android:textColor="#ffffffff" android:id="@id/com_playstation_companionutil_id_alert_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="11.0dip" android:layout_marginTop="17.0dip" android:layout_marginRight="11.0dip" android:text="" android:lineSpacingExtra="1.0dip" />
    <com.playstation.companionutil.CompanionUtilAdjustButton android:textSize="16.0dip" android:textColor="#ffffffff" android:id="@id/com_playstation_companionutil_id_alert_positive_button" android:background="@drawable/companionutil_drawable_alert_dialog_button" android:layout_width="fill_parent" android:layout_height="28.0dip" android:layout_marginLeft="11.0dip" android:layout_marginTop="15.0dip" android:layout_marginRight="11.0dip" android:layout_marginBottom="15.0dip" android:text="@string/com_playstation_companionutil_msg_ok" />
</o.ﺗ>

APK

PS4 Remote Play Port (https://forum.xda-developers.com/android/apps-games/ps4-remote-play-android-thread-t3068225)

Questions to ask before submission

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

danrspencer avatar Feb 27 '17 10:02 danrspencer

Is it possible to manually work around this issue for now?

danrspencer avatar Feb 27 '17 12:02 danrspencer

Bump! Any update on this issue? I'm dealing with special characters in classes, method names, and XML tag names!

aletorrado avatar Sep 28 '17 03:09 aletorrado

@aletorrado There is no update to report. Updates to bug reports will always be made in the respective bug report, so you don't need to worry. Any related update will be posted in here.

iBotPeaches avatar Sep 29 '17 11:09 iBotPeaches

I have struck this issue with v7.0.1 of the Netflix apk

matthuisman avatar Mar 08 '19 22:03 matthuisman

I have also struck this issue with an app i'm currently trying to recompile

mohammed-ali-1 avatar Aug 17 '19 09:08 mohammed-ali-1

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

gilbsgilbs avatar Oct 27 '19 16:10 gilbsgilbs

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 avatar Nov 29 '20 12:11 iBotPeaches

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

amspeople avatar Dec 07 '20 14:12 amspeople

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.

iBotPeaches avatar Dec 07 '20 14:12 iBotPeaches

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" />

alexcohn avatar Jul 22 '21 16:07 alexcohn

Can anyone please provide a sample apk with source code or the proguard configuration file to reproduce this issue?

Source code is not available for apps provided in above comments and issue

sriteja777 avatar Oct 19 '21 14:10 sriteja777

@sriteja777 did you managed to fix it somehow?

aravi365 avatar Jan 24 '22 19:01 aravi365

@sriteja777 here is an example of failing APK: https://file.io/xjeXQrwAXR6s

dimitry-ishenko avatar Feb 01 '22 17:02 dimitry-ishenko

@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?

dimitry-ishenko avatar Feb 01 '22 19:02 dimitry-ishenko

@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.

iBotPeaches avatar Feb 01 '22 19:02 iBotPeaches

@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.

dimitry-ishenko avatar Feb 01 '22 19:02 dimitry-ishenko

@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

  • https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/main/java/org/xmlpull/renamed/MXSerializer.java
  • https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java
  • https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java

iBotPeaches avatar Feb 01 '22 21:02 iBotPeaches

@aravi365 No I wasn't able to fix it.

sriteja777 avatar Feb 03 '22 16:02 sriteja777

@dimitry-ishenko Thanks for sharing that, but I already have some apks with this error. What I am looking is the source code of app that can reproduce this issue.

sriteja777 avatar Feb 03 '22 16:02 sriteja777

@sriteja777 oic. Sorry misunderstood. But IMHO you can create one yourself and just add an invalid character (eg, $) to an XML tag.

From what I understood it's aapt2 which causes the failure. And it in turn uses libexpat which doesn't support XML 1.0 r5 where they've allowed additional chars in XML tags.

dimitry-ishenko avatar Feb 03 '22 17:02 dimitry-ishenko

Any news on this?

Carb0xylate avatar Mar 12 '22 23:03 Carb0xylate

hi guys is anybody slove this problem ??

lawlit24 avatar Mar 23 '22 23:03 lawlit24

@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.

andrisi avatar May 06 '22 18:05 andrisi

Anyone figured out a solution here? Bumping against the same problem myself.

ardevd avatar Mar 20 '24 07:03 ardevd

Here is another XML that apktool struggles with. I presume it's due to R8 or DexGuard obfuscating the class names.

<?xml version="1.0" encoding="utf-8"?>
<ql.ࡩ᫋ᫎ android:id="@id/alertView" android:focusable="true" android:clickable="true" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <ImageView android:id="@id/alert_imageView_background" android:layout_width="0.0dip" android:layout_height="0.0dip" android:src="@null" android:scaleType="centerCrop" android:importantForAccessibility="no" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
    <LinearLayout android:gravity="center" android:orientation="vertical" android:id="@id/alert_container" android:background="@drawable/rebrand_alert_view_background" android:paddingTop="@dimen/grid_8x" android:paddingBottom="@dimen/grid_8x" android:layout_width="0.0dip" android:layout_height="wrap_content" android:minHeight="@dimen/grid_52x" android:paddingStart="@dimen/grid_4x" android:paddingEnd="@dimen/grid_4x" android:layout_marginHorizontal="@dimen/grid_12x" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent">
        <ImageView android:id="@id/alert_imageView_icon" android:layout_width="@dimen/grid_6x" android:layout_height="@dimen/grid_6x" android:importantForAccessibility="no" app:tint="@color/rebrand_icon_color" />
        <TextView android:id="@id/alert_textView_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/grid_2x" style="@style/Standard.Bold.Primary.Text" />
        <TextView android:gravity="center" android:id="@id/alert_textView_description" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/grid_4x" android:minLines="2" style="@style/Small.Regular.Primary.Text" />
    </LinearLayout>

@iBotPeaches Here's the full app that's giving me headache. Figured it might be of interest to take a look at.

If you try to run apktool d base.apk && apktool b base.apk you'll run into lots of not well-formed (invalid token). errors.

ardevd avatar Mar 20 '24 08:03 ardevd