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

开启混淆后,反射 inflate ViewBinding 时数组越界 #123

Closed
suchen2 opened this issue Nov 23, 2022 · 1 comment
Closed

开启混淆后,反射 inflate ViewBinding 时数组越界 #123

suchen2 opened this issue Nov 23, 2022 · 1 comment

Comments

@suchen2
Copy link

suchen2 commented Nov 23, 2022

在ViewBindUtil.kt文件中的 withGenericBindingClass 方法, 抛出异常: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

混淆后第三次的数组中只有一个元素,希望能帮忙提供一下解决方案,谢谢!
return block.invoke(genericSuperclass.actualTypeArguments[1] as Class<VB>)

f5b0efef5924ca50cec78630a733403

这是正常运行的日志,打印的数组 actualTypeArguments
4c0136ebf97aa043e6637d7f210697d

这是混淆后崩溃的日志
34368f12a83334a43d466ae77c7fa54

@suchen2
Copy link
Author

suchen2 commented Nov 23, 2022

给使用viewBinding和viewModel的module混淆文件里加上以下规则可解决

################ ViewBinding & DataBinding & ViewModel ###############
-keep class * extends androidx.lifecycle.ViewModel{*;}
-keep public interface androidx.viewbinding.ViewBinding
-keep class * implements androidx.viewbinding.ViewBinding{*;}
-keepclassmembers class * implements androidx.viewbinding.ViewBinding {
  public static * inflate(android.view.LayoutInflater);
  public static * inflate(android.view.LayoutInflater, android.view.ViewGroup, boolean);
  public static * bind(android.view.View);
}

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

2 participants