Meituan-Dianping / Robust

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Apache License 2.0
4.4k stars 805 forks source link

修复第三方库混淆出r文件与R文件冲突导致报错问题。eg:Caused by: java.lang.RuntimeException: ca… #465

Open smuwjs opened 2 years ago

smuwjs commented 2 years ago

背景: 项目打包时遇到很多第三方库混淆时会出现第三方库包名+r文件与项目生成的第三方库包名+R文件冲突导致报错问题,使用Robust才会报错,不使用是正常的。有的第三方库无法联系到开发者,如果能在Robust层面上解决,会是一种比较好的方式。

有问题的第三方库: 华为推送:maven { url 'http://developer.huawei.com/repo/' } com.huawei.hms:push:5.0.3.301

报错: Caused by: java.lang.RuntimeException: cannot find com.huawei.hms.hatool.r: com.huawei.hms.hatool.R found in com/huawei/hms/hatool/r.class at javassist.CtClassType.getClassFile2(CtClassType.java:202) at javassist.CtClassType.getModifiers(CtClassType.java:407) at robust.gradle.plugin.asm.AsmInsertImpl.insertCode(AsmInsertImpl.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

功能说明: 尝试directoryInputs和jarInputs分别用独立的ClassPool可以修复,目前未发现更好的办法。

备注: 测试暂未发现BUG,准备上到线上环境,可以看看是否有问题。