APKEditor: Building back from decompilation to apk fails

1.APKEditor version: 1.2.0 2.apk file: Settings.apk

3.run: java -jar APKEditor.jar d -i Settings.apk

00.000 I: [DECOMPILE] Decompiling ...
   Input: Settings.apk
 Output: Settings_decompile_null
 Type: json
 Split: false
 ---------------------------- 
00.020 I: [DECOMPILE] Loading ...
00.579 I: [DECOMPILE] Initializing android framework ...
00.579 I: [DECOMPILE] Loading android framework for version: 33
00.614 I: [DECOMPILE] Initialized framework: android-33
00.614 I: [DECOMPILE] Decompiling to JSON ...
00.659 I: [DECOMPILE] [SANITIZE]: Sanitizing paths ...
00.663 [DECOMPILE] [SANITIZE]: REN: 'META-INF/external__kotlinx.coroutines__android_common__kotlinx_cor                                                                                                       00.663 [DECOMPILE] [SANITIZE]: REN: 'META-INF/packages__apps__MiuiSettingsLib__android_common__MiuiSettingsLib.kotlin_module' -> 'META-INF/alias_45341996'
00.667 I: [DECOMPILE] [SANITIZE]: DONE = 10572
03.648 I: [DECOMPILE] Dumping signatures ...
03.648 I: [DECOMPILE] Saved to: Settings_decompile_null
03.648 I: [DECOMPILE] Done

do not make any changes.

4.run: java -jar APKEditor.jar b -i Settings_decompile_null

00.000 I: [BUILD] Building ...
   Input: Settings_decompile_null/base
 Output: Settings_decompile_null_out.apk
 ---------------------------- 
00.019 I: [BUILD] Scanning JSON directory ...
00.103 I: [BUILD] Restoring file path ...
00.104 I: [BUILD] Building resources table: resources.arsc

Unexpected error:
java.io.IOException: resources.arsc: JSONObject["style"] not found.
java.lang.IllegalArgumentException: java.io.IOException: resources.arsc: JSONObject["style"] not found.
	at com.reandroid.apk.ApkModule.getTableBlock(ApkModule.java:566)
	at com.reandroid.apk.ApkModule.getTableBlock(ApkModule.java:573)
	at com.reandroid.apk.ApkModule.listResFiles(ApkModule.java:398)
	at com.reandroid.apk.ApkModule.listResFiles(ApkModule.java:394)
	at com.reandroid.apk.PathMap.restore(PathMap.java:37)
	at com.reandroid.apk.ApkJsonEncoder.restorePathMap(ApkJsonEncoder.java:82)
	at com.reandroid.apk.ApkJsonEncoder.scanDirectory(ApkJsonEncoder.java:48)
	at com.reandroid.apkeditor.compile.Builder.buildJson(Builder.java:69)
	at com.reandroid.apkeditor.compile.Builder.run(Builder.java:49)
	at com.reandroid.apkeditor.compile.Builder.execute(Builder.java:159)
	at com.reandroid.apkeditor.Main.execute(Main.java:65)
	at com.reandroid.apkeditor.Main.main(Main.java:38)
Caused by: java.io.IOException: resources.arsc: JSONObject["style"] not found.
	at com.reandroid.apk.SingleJsonTableInputSource.getTableBlock(SingleJsonTableInputSource.java:68)
	at com.reandroid.apk.ApkModule.loadTableBlock(ApkModule.java:652)
	at com.reandroid.apk.ApkModule.getTableBlock(ApkModule.java:560)
	... 11 more

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 50 (24 by maintainers)

Commits related to this issue

Most upvoted comments

Check the latest release : V1.2.1

I found issue on duplicate resource names, check this update APKEditor-1.2.0-UPDATE-04.jar

Good ! We have solved a lot of issue on the way. I will update repos with proper release and I will credit you for your contribution. Thank you!

No point closing this issue without finding out the exact problem. I am making new separate program to compare resources in detail. I will get back to you when it is done

Check the latest release : V1.2.1

After testing, both xml and json are working fine.

Thanks for your work.

  • DIMENSION:

    1. When you divide/multiply integers to float you will loose fractional values , e.g if you encode-decode-encode value 1.0dp without any adjustment the result will be 0.999999dp, that is why I tried to round up digits with best result possible.
    2. Encoding dimension to integer is a bit complicated check AOSP Line 379-386 e.g value 180.0dp can be encoded to integer 46081 or 5898257 if you decode this values the result is the same. So you might see different integer result on JSON but it is the same.
  • STRING:

    1. 2 . There is still a problem with the string, the content lacks spaces

      Yes I confirm, it will be fixed

I will fix this and other issues and get back to you

thanks for your work.

  • Sorry I don’t know chinese and your screenshots are not helping me at all. If you place it here in raw strings I might be able to copy and do string search it. for example:
Correct-Text Wrong-Text
无无无无 寸寸寸寸寸
uuuuuu vvvvvvvvvv
wwwww xxxxxxxxx
  • Is this problem happening on chinese (zh-rCN) language only ? If not please change it to english for better communication.

  • Here is my builds based on your original file, now tell me which one is working and which is not (sign it if required)

  1. original > decompile to xml > compile Settings_decompile_xml_out.apk
  2. apk from 1 > decompile to json > compile Settings_decompile_xml_out_decompile_json_out.apk
  • Is there a way for me to install and test it on emulator under linux ?

Here I made a massive change you can test it with APKEditor-1.2.0-UPDATE-01.jar

  • The only problem I found was it doesn’t remove unused strings from pool

This is the value_xml(com.android.settings) file of Settings

<?xml version='1.1' encoding='utf-8' standalone='yes' ?>
<MIUI_Theme_Values>
<string name="miui_more_special_feature">探索功能</string>
<string name="data_usage_summary_title">流量情况</string>
<string name="ai_button_title">智能按键</string>
<string name="emergency_sos_title">紧急求助</string>
<string name="my_device">我的设备</string>
<string name="about_settings">关于手机</string>
<string name="header_category_wireless_networks">网络连接</string>
<string name="sim_management_title">双卡网络</string>
<string name="wifi_settings_title">无线网络</string>
<string name="bluetooth_settings_title">蓝牙连接</string>
<string name="wifi_tether_settings_title">个人热点</string>
<string name="app_name_na">网络助手</string>
<string name="vpn_settings_title">代理设置</string>
<string name="radio_controls_title">更多方式</string>
<string name="display_settings">显示设置</string>
<string name="sound_vibrate_settings">声音振动</string>
<string name="lock_settings">锁屏密码</string>
<string name="lock_settings_with_fingerprint">密码指纹</string>
<string name="status_bar_settings">通知设置</string>
<string name="infinity_display_title">全屏手势</string>
<string name="second_space">手机分身</string>
<string name="do_not_disturb_mode">勿扰模式</string>
<string name="power_usage_summary_title">电量性能</string>
<string name="pref_edge_handgrip">边缘触控</string>
<string name="game_mode_settings">游戏模式</string>
<string name="miui_lab_settings">实验功能</string>
<string name="oldman_mode_entry_name">极简桌面</string>
<string name="other_advanced_settings">更多设置</string>
<string name="xiaomi_account">小米帐号</string>
<string name="sync_settings">自动同步</string>
<string name="system_app_settings">系统应用</string>
<string name="applications_settings">更多应用</string>
<string name="xspace">应用双开</string>
<string name="permission_manager">授权管理</string>
<string name="application_lock_name">应用守护</string>
<string name="usage_state_app_timer">屏幕时间</string>
<string name="launcher_title">桌面管理</string>
<string name="account_list">其他账号</string>
<string name="header_category_accounts">账号管理</string>
<string name="home_title">桌面管理</string>
<string name="aod_and_lock_screen_settings_title">息屏锁屏</string>
<string name="password_security_settings_title">密码安全</string>
<string name="security_settings_title">密码管理</string>
<string name="lock_screen_settings_title">锁屏管理</string>
<string name="security_keyguard_category_name">锁屏管理</string>
<string name="password_and_security">密码安全</string>
<string name="connection_and_sharing">连接共享</string>
<string name="notification_control_center">通知控制</string>
<string name="feedback_settings">服务反馈</string>
<string name="power_usage_summary_title_new">电量性能</string>
<string name="wallpaper_settings_title">桌面壁纸</string>
<string name="personalize_title">桌面壁纸</string>
<string name="wallet_header_title">钱包支付</string>
<string name="card_holder_header_title">钱包支付</string>
<string name="sound_haptic_settings">声音触感</string>
<string name="security_center_title">安全管理</string>
<string name="fingerprint_face_password_unlock">密码管理</string>

<string-array name="handy_mode_size_text_entries">
<item>4.5 英寸</item>
<item>4.0 英寸</item>
<item>3.5 英寸</item>
<item>2.5 英寸</item>
<item>2.0 英寸</item>
<item>1.5 英寸</item>
<item>1.0 英寸</item>
<item>0.5 英寸</item>
</string-array>
......
</MIUI_Theme_Values>
 

some of them don’t work

<string name="personalize_title">桌面壁纸</string>
<string name="display_settings">显示设置</string>
<string name="sound_haptic_settings">声音触感</string>
...

It’s possible that it has something to do with the frame. json can guarantee 100% correctness. If no progress is made, this issue can be closed first.

Thanks for your work.

Ohh I made silly mistake here. Check the latest update

Question 1: I found that some resource hooks in the apk compiled back using xml are invalid (third-party themes can change the text options in the settings, but some do not take effect).

I can’t figure out where exactly this problem is. I compared (using custom program byte level) files built with json & xml, most differences are irrelevant except config size 64(xml) & 48(json) and I doubt this fixes your issue.

I updated releases, you can test now and it will be better if you can get some stacktraces/logs

  • Color
  • Style string

Seems to be fixed now, check updates

Fixed major issues and release updated, you can test it now

smallwindow_icon.xml.json:

Fixed with this commit I will update releases latter after fixing other issues

Why is json parsing correct and xml wrong? Are their implementations different?

Good question, Consider dex(dalvik) decompiling we can decompile/compile to smali or java but most of the times java gets error

  • converting ARSC to/from XML is like converting DEX to/from JAVA
  • converting ARSC to/from JSON is like converting DEX to/from SMALI

Decompiling to XML is not 1:1 it is based on guess and assumptions e.g. you have a value 1234 there is no direct way to tell for XML this is STRING or INTEGER or FLOAT but for JSON you simply specify it with value_type:"xxxx". XML by itself has its own limitation/weakness.

This is the reason why i came up with idea of JSON format as an agent between low level byte code and humans to modify binary resources with 100% accuracy. If you check commits history I added XML support lately because most developers are used to XML and got confused with the new JSON.

I always recommend to use JSON format (if you are good at it) it is guaranteed to be 100% accurate.

Anyways we will keep improving XML conversion but there is no logical way to reach 100% error free.

2.Question 1 still exists. 3.Because there are special characters in the original AndroidManifest.xml, it can also be expected.

The developer of this apk put those characters AndroidManifest.xml for some reason or mistake. Not the problem of the parser. Check AndroidManifest.xml.json

      {
       "node_type": "text",
       "text": " ' "
      }

The error was DIMESION value encode/decode. On this case raw value -47615 supposed to be decoded as -186.0dp. Now this issue seems to be fixed and check the latest update.

You are pointing out good issues, hope you will keep doing same. Thank You !

I conducted a test, resources.arsc is no longer wrong. but the UI layout is not correct, is there a problem with xml parsing? I used the recompiled apk (xml) to decompile to json format again, and found that it could not match the original apk decompiled json file in some places.

The left side uses the xml format and decompiles it into json again.(Settings_decompile_xml_out_decompile_json) Settinhs_test.zip example: base/res-json/res/drawable-sw600dp-v13/core_scan_gesture_broadside.xml.json 1 2

I thought I fixed this issue a while ago. Now I fixed the issue and updated all along with the release APKEditor-1.2.0.jar Your apk should work fine with this