修复第三方库混淆出r文件与R文件冲突导致报错问题。eg:Caused by: java.lang.RuntimeException: ca… #465
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
背景:
项目打包时遇到很多第三方库混淆时会出现第三方库包名+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,准备上到线上环境,可以看看是否有问题。