简体   繁体   English

Android Facebook 的 ProGuard 设置

[英]Android ProGuard settings for Facebook

I finally found out why my app crashes built for release.我终于找到了为什么我的应用程序崩溃是为发布而构建的。 ProGuard was indeed stripping code from my application but i prevented this by manually adding the classes with the keep command in the proguard-android.txt (found in the sdk). ProGuard 确实从我的应用程序中剥离了代码,但我通过在 proguard-android.txt(在 sdk 中找到)中使用 keep 命令手动添加类来阻止这种情况。

For Facebook I used:对于 Facebook,我使用了:

-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient { 
    <methods>; 
}

But I think I'm still missing something.但我想我仍然缺少一些东西。 The app is crash free now but I can't log in to Facebook and use Open Graph.该应用程序现在没有崩溃,但我无法登录 Facebook 并使用 Open Graph。 When I built in debug mode this all works fine.当我在调试模式下构建时,一切正常。

What are your proguard settings for using Facebook and Facebook's Open Graph?您使用 Facebook 和 Facebook 的 Open Graph 的混淆设置是什么?

EDIT编辑

This are my manually added commands for ProGuard:这是我为 ProGuard 手动添加的命令:

-dontwarn android.support.**

# ActionBarSherlock 

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

-keep interface android.support.** { *; } 

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

-keep interface com.actionbarsherlock.** { *; } 




# Keep line numbers to alleviate debugging stack traces 

-renamesourcefileattribute SourceFile 

-keepattributes SourceFile,LineNumberTable

-keepclassmembers class * implements java.io.Serializable
{
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient { 
    <methods>; 
}

EDIT 2 So the problem for not logging in was that I used my debug hash key instead of my release hash key.编辑 2所以不登录的问题是我使用了我的调试 hash 密钥而不是我的发布 hash 密钥。 Changed that in my app settings (developers.facebook.com) and found out that my app finally logs in but crashes after login.在我的应用程序设置 (developers.facebook.com) 中更改了它,发现我的应用程序最终登录但在登录后崩溃。

Dont know if this still is a ProGuard problem but it returned this error:不知道这是否仍然是 ProGuard 问题,但它返回了这个错误:

04-02 11:47:31.815: E/AndroidRuntime(9093): FATAL EXCEPTION: main
04-02 11:47:31.815: E/AndroidRuntime(9093): com.facebook.ab: com.facebook.b.e got an unexpected method signature: public abstract com.facebook.b.b com.facebook.b.b.a(java.lang.Class)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.b.f.a(SourceFile:400)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.b.e.b(SourceFile:546)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.b.e.invoke(SourceFile:470)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at $Proxy1.a(Native Method)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.bb.a(SourceFile:124)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.ar.a(SourceFile:264)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.facebook.as.run(SourceFile:1240)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at android.os.Handler.handleCallback(Handler.java:615)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at android.os.Looper.loop(Looper.java:137)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at android.app.ActivityThread.main(ActivityThread.java:4931)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at java.lang.reflect.Method.invokeNative(Native Method)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at java.lang.reflect.Method.invoke(Method.java:511)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
04-02 11:47:31.815: E/AndroidRuntime(9093):     at dalvik.system.NativeStart.main(Native Method)
04-02 11:47:31.820: W/ActivityManager(2130):   Force finishing activity com.xxxxx.xxxx/com.xxxxx.views.MainActivity
04-02 11:47:32.360: W/ActivityManager(2130): Activity pause timeout for ActivityRecord{4289ca58 com.xxxxx.xxxxx/com.xxxxx.xxxxx.MainActivity}

fixed: 固定:

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

instead of: 代替:

-keepattributes Signature
-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient { 
    <methods>; 
}

Also be sure to check your hash key in your facebook app settings. 另外,请务必在Facebook应用设置中检查您的哈希键。

In my case your solution 就我而言,你的解决方案

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

works, but I had to keep 工作,但我必须保持

-keepattributes Signature

In order to get everything working. 为了让一切正常。

I solved this problem by adding我通过添加解决了这个问题

implementation 'androidx.annotation:annotation:1.0.0'

reference: Add the Audience Network SDK to your Android App参考: 将Audience Network SDK添加到您的Android App

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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