Robertoq Robertoq - 3 months ago 23
Android Question

View's onClick not working in ViewPager/Fragment if proguard enabled

I have a

ViewPager
in my Activity which is show Fragments by
FragmentStatePagerAdapter
. Inside the Fragments there are some view from xml and some dynamically created. When from xml I using
ButterKnife
to handle click event and for generated views. I just use the
setOnClickListener(new View.OnClickListener...)
from code.
It's working but when I enable
ProGuard
only here (ViewPager.Fragments.View) click not working but everywhere else in the app yes.

My gradle:

release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}


proguard-rules.pro:

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

-keep class com.parse.** { *; }
-dontwarn com.parse.**

-dontwarn com.squareup.picasso.**

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keep class android.support.v4.** { *; }


What is the correct ProGuard settings?

Answer

Use this :

-libraryjars   libs/android-support-v4.jar
-dontwarn android.support.**
-keep class android.support.v4.** { *; }  
-keep interface android.support.v4.app.** { *; }
-keepattributes *Annotation*
Comments