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

报错,求指教 #64

Open
liguangze opened this issue Apr 6, 2023 · 1 comment
Open

报错,求指教 #64

liguangze opened this issue Apr 6, 2023 · 1 comment

Comments

@liguangze
Copy link

image
你好我在基类上写上了,为什么报错呢
ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
Class cls = (Class) type.getActualTypeArguments()[0];
try {
Method inflate = cls.getDeclaredMethod("inflate", LayoutInflater.class);
viewBinding = (T) inflate.invoke(null, getLayoutInflater());
setContentView(viewBinding.getRoot());
} catch (Exception e) {
e.printStackTrace();
}

2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: java.lang.NoSuchMethodException: inflate [class android.view.LayoutInflater]
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.Class.getMethod(Class.java:624)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.Class.getDeclaredMethod(Class.java:586)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.akax.haofangfa.pen.base.BaseActivity.onCreate(BaseActivity.java:68)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.akax.haofangfa.pen.ui.MainActivity.onCreate(MainActivity.java:23)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.Activity.performCreate(Activity.java:6279)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2606)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1444)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.os.Looper.loop(Looper.java:148)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5647)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
2023-04-06 15:44:54.255 6177-6177/com.akax.haofangfa.pen W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

@tanranran
Copy link

proguard-rules.pro 中加上这些

AGP 8以上,因为android.enableR8.fullMode会强制开启,还需要加上以下三行

-keep class * implements androidx.viewbinding.ViewBinding {*;}

-keepclassmembers class * implements androidx.viewbinding.ViewBinding {
public static ** bind(***);
public static ** inflate(...);
}

-keep,allowobfuscation,allowshrinking class 你的包名. BaseBindingActivity

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