简体   繁体   中英

ProGuard still stripping Facebook code? (Or disable ProGuard!!)

I've really had it with ProGuard / Release builds for Android. I've tried to upload my app to the play store but every time I fix something another error shows up. And this only happens in release mode. After a lot of trial and erros my app is in the play store. Previously it would crash on startup (fixed by adding the classes in ProGuard settings). Then Facebook wouldnt sign in (fixed by adding

 -keep class com.facebook.** {
   *;
}

to the ProGuard settings.

Now my app crashes when I try to connect with Facebook's Open Graph and post a message. I receive this error and really cant find anything about it on the web:

04-02 18:09:20.160: E/AndroidRuntime(16163): FATAL EXCEPTION: main
04-02 18:09:20.160: E/AndroidRuntime(16163): com.facebook.FacebookGraphObjectException: Factory can't proxy method: public abstract java.lang.String com.xxxx.views.am.a()
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.model.GraphObject$Factory.verifyCanProxyClass(SourceFile:270)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.model.GraphObject$Factory.createGraphObjectProxy(SourceFile:196)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.model.GraphObject$Factory.access$0(SourceFile:195)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.model.GraphObject$Factory$GraphObjectProxy.proxyGraphObjectMethods(SourceFile:530)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.model.GraphObject$Factory$GraphObjectProxy.invoke(SourceFile:470)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at $Proxy3.cast(Native Method)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.facebook.Response.getGraphObjectAs(SourceFile:124)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.xxxxx.views.aa.a(SourceFile:432)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.xxxxxx.views.aa.a(SourceFile:419)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.xxxxx.views.ag.a(SourceFile:377)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.xxxxx.views.ag.onPostExecute(SourceFile:1)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.os.AsyncTask.finish(AsyncTask.java:631)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.os.Looper.loop(Looper.java:137)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at android.app.ActivityThread.main(ActivityThread.java:4931)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at java.lang.reflect.Method.invokeNative(Native Method)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at java.lang.reflect.Method.invoke(Method.java:511)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
04-02 18:09:20.160: E/AndroidRuntime(16163):    at dalvik.system.NativeStart.main(Native Method)

Is ProGuard still stripping out code Im using? And what settings would fix this? For the record.. Everything works great in build mode.

Another question. Is it possible to just disable ProGuard? I think is really useless and only give more problems.

ProGuard is disabled by default, also in release builds. You have enabled it yourself by enabling the proguard.config line in your project.properties file. You can disable it again by commenting out the line.

ProGuard can be useful, but you need to configure it for any reflection in your application. In this case, the Facebook API is performing reflection on your own classes. Looking at the code of the API, it is searching for getters, setters, and annotated methods in extensions of GraphObject. ProGuard renames or even removes those by default, because it doesn't (and generally can't) know about the reflection. Others who are using the API may know which classes, fields, and methods need to be preserved. Classes that you pass to the API and that have some method naming conventions are probably good candidates.

This problem cost me hours. The solution is to exclude the class where you build the OpenGraphObject in addition to your current proguard code. So you can use ProGuard instead of turn it off.

 -keep public class com.facebook.ads.** {
 public *;
}
 -keep class com.google.ads.mediation.facebook.FacebookAdapter {
 *;
   }

-dontwarn com.facebook.ads.internal.** -dontwarn com.facebook.ads.**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM