virjarRatel / ratel-core

平头哥的核心代码
579 stars 277 forks source link

repkg failure 重打包失败 #5

Closed zhupeng-pro closed 2 years ago

zhupeng-pro commented 2 years ago

step1: download the project from github step2: ./script/create-dist.sh step3: ./script/build_ratel_manager.sh step4: repkg my apk:

$ ./script/dist/ratel.sh app-debug.apk use /Users/yueyueniao/android-safe/ratel-core-master/script/dist/res/container-builder-repkg-2.0.0-SNAPSHOT.jar assemble new apk for app-debug.apk build with default certificate ratel build param: -s -w /Users/yueyueniao/.ratel-working-repkg -c /Users/yueyueniao/android-safe/ratel-core-master/script/dist/res/monthly_temp.txt app-debug.apk use ratel engine: rebuildDex build serialNo: ratel_85576517-0fcc-4218-9255-504a9bcd1239 work dir: /Users/yueyueniao/.ratel-working-repkg apk info [packageName:com.example.helloworld,appEntryClass: com.example.helloworld.MainActivity] warning: can not find class: android.app.AppComponentFactory handle inject for class: androidx.core.app.CoreComponentFactory Exception in thread "main" java.lang.AssertionError at external.com.android.dex.Dex$Section.writeStringData(Dex.java:723) at external.com.android.dx.merge.DexMerger$1.write(DexMerger.java:1433) at external.com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:298) at external.com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:1435) at external.com.android.dx.merge.DexMerger.merge(DexMerger.java:215) at com.virjar.ratel.builder.injector.CodeInjectorV2.doInject$187f0e2e(CodeInjectorV2.java:111) at com.virjar.ratel.builder.mode.RatelPackageBuilderRepackage.handleTask$16585ff8(RatelPackageBuilderRepackage.java:56) at com.virjar.ratel.builder.ratelentry.Main.ratelMain(Main.java:7174) at com.virjar.ratel.builder.ratelentry.Main.main(Main.java:67) assemble ratel apk failed

定位问题: container-builder-repkg-2.0.0-SNAPSHOT.jar 生成的jar包好像有问题,不知道什么原因

virjar commented 2 years ago

apk发出来看看

zhupeng-pro commented 2 years ago

app-debug.apk.zip

一个简单的app,点击button展示toast "hello world!"

virjar commented 2 years ago

ratel_issue_5

dex的常量池里面有一个长度为22万的字符串。dx库重建dex的时候要求字符串的长度不能超过65535. https://android.googlesource.com/platform/libcore/+/7047230/dex/src/main/java/com/android/dex/Mutf8.java#110

这应该是命中了dx库的一个bug,因为dx库实际上已经废弃很多年了。现在Android Studio内置的工具链使用的R8进行dex构建处理。

https://r8.googlesource.com/r8/+/refs/heads/main/src/main/java/com/android/tools/r8/dex/FileWriter.java#563

暂时修改dx逻辑解决这个问题,你再测试下

zhupeng-pro commented 2 years ago

解决了!dex的String ID list中确实有个item长度很大,感谢大佬👍