Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R8 full mode 完整模式兼容问题 #471

Open
liujingxing opened this issue Oct 28, 2023 · 2 comments
Open

R8 full mode 完整模式兼容问题 #471

liujingxing opened this issue Oct 28, 2023 · 2 comments

Comments

@liujingxing
Copy link
Owner

RxHttp 版本 v3.2.0

通过android.enableR8.fullMode=true开启R8完整模式,或将AGP升级至8.0及以上版本,将默认开启完整模式,此时执行以下代码,将发生闪退

RxHttp.get("...")
   .toXxx(object: SmartParser<Xxx>(){})   //通过匿名内部类,创建任意继承TypeParser的类
   ...

闪退日志

java.lang.RuntimeException: Missing type parameter.
   at rxhttp.wrapper.utils.TypeUtil.getActualTypeParameters(TypeUtil.java:23)
   at rxhttp.wrapper.parse.TypeParser.<init>(TypeParser.java:18)
   at com.example.httpsender.parser.ResponseParser.<init>(ResponseParser.kt:32)
@liujingxing
Copy link
Owner Author

liujingxing commented Oct 28, 2023

出现该问题的原因是,完整模式下,对于没有keep的类,将会擦出泛型信息

目前有3个解决方案

1、手动关闭完整模式,在gradle.properties文件中添加以下代码

android.enableR8.fullMode=false

2、添加以下规则到proguard-rules.pro文件中

-keepattributes Signature
-keep,allowobfuscation,allowshrinking class * extends rxhttp.wrapper.parse.TypeParser

3、升级RxHttp至v3.2.1或更高版本

@liujingxing
Copy link
Owner Author

liujingxing commented Oct 28, 2023

如果项目中有自定义解析器,并且使用了类似于BaseResponse<T>的类,也要添加以下规则到gradle.properties文件中,其它带有泛型的实体类同理

-keep,allowobfuscation,allowshrinking class xxx.xxx.BaseResponse

其中xxx.xxx是类路径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant