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

Problem with ProGuard in custom view #38

Closed
Anton111111 opened this issue Feb 2, 2021 · 8 comments
Closed

Problem with ProGuard in custom view #38

Anton111111 opened this issue Feb 2, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@Anton111111
Copy link

You can see issue with proguard on this example. If set minifyEnabled to true then app will crash on start:
https://github.com/Anton111111/NavigationLikeInstagram/blob/vbpd-bug/app/src/main/java/com/anton111111/navigation/ui/CustomView.kt

If change minifyEnabled to false app started without problem:
https://github.com/Anton111111/NavigationLikeInstagram/blob/vbpd-bug/app/build.gradle

@alaegin
Copy link
Contributor

alaegin commented Feb 20, 2021

@Anton111111 Try to add this rule to your proguard config.
It seems that the original distribution lucks of some rules.

-keep class * implements androidx.viewbinding.ViewBinding {
  public static *** bind(android.view.View);
  public static *** inflate(android.view.LayoutInflater);
  public static *** inflate(android.view.LayoutInflater, android.view.ViewGroup, boolean);
}

@Anton111111
Copy link
Author

@alaegin , doesn't work with this rules too

@kirich1409
Copy link
Collaborator

@Anton111111 , please send your crash log?

@kirich1409 kirich1409 self-assigned this Feb 20, 2021
@kirich1409 kirich1409 added the enhancement New feature or request label Feb 20, 2021
@Anton111111
Copy link
Author

@kirich1409 ,i get the following exception on the sample (to check sample see first message):
2021-02-21 11:09:32.132 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.anton111111.navigation, PID: 7283 android.view.InflateException: Binary XML file line #9 in com.anton111111.navigation:layout/auth_fragment: Binary XML file line #9 in com.anton111111.navigation:layout/auth_fragment: Error inflating class com.anton111111.navigation.ui.CustomView Caused by: android.view.InflateException: Binary XML file line #9 in com.anton111111.navigation:layout/auth_fragment: Error inflating class com.anton111111.navigation.ui.CustomView Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:852) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) at android.view.LayoutInflater.inflate(LayoutInflater.java:680) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at androidx.fragment.app.Fragment.l0(:1922) at androidx.fragment.app.Fragment.L0(:2950) at b.k.b.s.f(:515) at b.k.b.s.m(:282) at b.k.b.m.Z(:2177) at b.k.b.m.T0(:2094) at b.k.b.m.W(:1990) at b.k.b.m$g.run(:524) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.NoSuchMethodException: com.anton111111.navigation.databinding.CustomViewBinding.inflate [class android.view.LayoutInflater, class android.view.ViewGroup] at java.lang.Class.getMethod(Class.java:2072) at java.lang.Class.getMethod(Class.java:1693) at c.a.a.h.f.a(:60) at c.a.a.h.e.b(:21) at c.a.a.f$b.a(:37) at c.a.a.f$b.j(Unknown Source:2) at c.a.a.d.b(:33) at c.a.a.d.a(:25) at com.anton111111.navigation.ui.CustomView.getViewBinding(Unknown Source:7) at com.anton111111.navigation.ui.CustomView.a(:38) at com.anton111111.navigation.ui.CustomView.<init>(:30) at com.anton111111.navigation.ui.CustomView.<init>(:20) at com.anton111111.navigation.ui.CustomView.<init>(:19) at java.lang.reflect.Constructor.newInstance0(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:343)  at android.view.LayoutInflater.createView(LayoutInflater.java:852)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)  at android.view.LayoutInflater.inflate(LayoutInflater.java:680)  at android.view.LayoutInflater.inflate(LayoutInflater.java:532)  at androidx.fragment.app.Fragment.l0(:1922)  at androidx.fragment.app.Fragment.L0(:2950)  at b.k.b.s.f(:515)  at b.k.b.s.m(:282)  at b.k.b.m.Z(:2177)  at b.k.b.m.T0(:2094)  at b.k.b.m.W(:1990)  at b.k.b.m$g.run(:524)  at android.os.Handler.handleCallback(Handler.java:938)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:223)  at android.app.ActivityThread.main(ActivityThread.java:7656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

@Anton111111
Copy link
Author

Anton111111 commented Feb 21, 2021

@kirich1409 , @alaegin ,i've fixed my problem with small tuned of @alaegin advice.
I expanded the advice by adding a line: "public static *** inflate(android.view.LayoutInflater, android.view.ViewGroup);"

My complet proguard rule:

-keep class * implements androidx.viewbinding.ViewBinding {
public static *** bind(android.view.View);
public static *** inflate(android.view.LayoutInflater);
public static *** inflate(android.view.LayoutInflater, android.view.ViewGroup);
public static *** inflate(android.view.LayoutInflater, android.view.ViewGroup, boolean);
}

@kirich1409
Copy link
Collaborator

Will be fixed in 1.4.3

@Anton111111
Copy link
Author

@kirich1409 , on last release (1.4.4) still doesn't works.
To fix it i remove "allowshrinking" from proguard rules.

@kirich1409 kirich1409 reopened this Mar 10, 2021
@kirich1409
Copy link
Collaborator

Will be fixed in the next release

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

No branches or pull requests

3 participants