Android SearchView does not work

前端 未结 8 1756
心在旅途
心在旅途 2021-01-11 17:25

I tried to update all the libraries, but i still got errors. I am able to run the app on the simulator, but when I export the APK and run it on a real android device, the ap

8条回答
  •  [愿得一人]
    2021-01-11 18:02

    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 class android.support.v4.app.** { *; }
       -keep interface android.support.v4.app.** { *; }
       -keep class android.support.v7.app.** { *; }
       -keep interface android.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 public class * extends android.support.v7.widget.SearchView {
       public (android.content.Context);
       public (android.content.Context, android.util.AttributeSet);
    }
    

    The constructors are specifically mentioned to avoid the error:

    java.lang.NoSuchMethodException:  [class android.content.Context]
    

提交回复
热议问题