Android Searchview Does Not Work
Solution 1:
Add following code to proguard-rules.pro
-keep classandroid.support.v7.widget.SearchView { *; }
Solution 2:
Have you enabled Proguard in your build? If so, you may want to ensure that the appcompat libraries are in the Proguard exclusion list (in proguard.cfg). A brute force approach is to keep all the support library classes with:
-keep classandroid.support.v4.app.** { *; }
-keep interfaceandroid.support.v4.app.** { *; }
-keep classandroid.support.v7.app.** { *; }
-keep interfaceandroid.support.v7.app.** { *; }
In my case, I had a class that extended the support library's SearchView so I added this to my proguard.cfg:
-keep publicclass * extendsandroid.support.v7.widget.SearchView{
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
}
The constructors are specifically mentioned to avoid the error:
java.lang.NoSuchMethodException: <init> [classandroid.content.Context]
Solution 3:
After long hours of research a simple solution of this problem i.e just add
-keep classandroid.support.v7.widget.SearchView { *; }
in app/proguard/android.proguard file of AndroidStudio.
Cheers!
Solution 4:
I (also) got
Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setOnQueryTextListener(android.support.v7.widget.ao)'on a nullobject reference
when launching my release build (with proguard/minify enabled).
Adding this to the proguard rules fixed it:
-keep classandroid.support.v7.widget.SearchView { *; }
This will keep the SearchView widget but will still allow proguard to throw away any other support library classes that you're not using, so you keep your release build nice and tidy.
Solution 5:
Required minimum to proguard-rules.pro
-keep classandroid.support.v7.widget.SearchView {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
}
Post a Comment for "Android Searchview Does Not Work"