【问题标题】:Proguard and Google SDK / Facebook SDK missing methodsProguard 和 Google SDK / Facebook SDK 缺少方法
【发布时间】:2017-09-06 21:32:54
【问题描述】:

我很难使用 proguard 编译客户的应用程序(我在正确的文件夹中安装了最新版本的 proguard)。 --edit--: 我没有使用最新版本,因为安装了多个副本并且构建脚本没有使用正确的。

我创建了一个proguard.cfg 文件,可以解决大部分编译错误。 该应用针对最新的 android SDK (8) 并将 minSdk 设置为 21。

还有2个编译错误:

#1>PROGUARD : warning : com.google.android.gms.internal.zzx: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzx$zza
#1>PROGUARD : warning : com.google.android.gms.internal.zzx$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzx$zza

在 stackoverflow 上,在 java 上,他们通过向 Gradle 添加一些东西来解决问题。在 Xamarin 上......你不能。

通过在 proguard 文件中添加 dontwarn 指令,我能够忽略 2 个警告。 然后它几乎可以编译、部署和运行。 几乎所有应用程序都运行良好。
除了:
- 谷歌身份验证,崩溃
- facebook 身份验证,崩溃
- 谷歌位置(保险丝)崩溃。

崩溃是由于缺少方法引起的。已被 proguard 删除的方法。

对于脸书:

NoSuchMethodError: no non-static method"Lcom/facebook/internal/CallbackManagerImpl;.onActivityResult(IILandroid/content/Intent;)Z"
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <e3048811891c45499b4d89daf4d10667>:0
at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <48117e3895d549baa70c8cbd8592b31c>:0
at Android.Runtime.JNIEnv.GetMethodID (System.IntPtr kls, System.String name, System.String signature) [0x00007] in <758a804725c84b16bcab28b784c87cae>:0
at Xamarin.Facebook.ICallbackManagerInvoker.OnActivityResult (System.Int32 requestCode, System.Int32 resultCode, Android.Content.Intent data) [0x00015] in <53b39e4821ad43cba06dc6bebd7ae5f1>:0
at Appname.Droid.Views.Signup.SignInActivity.OnActivityResult

对于谷歌身份验证:

NoSuchMethodError: no non-static method "Lcom/google/android/gms/auth/api/signin/internal/zzc;.silentSignIn(Lcom/google/android/gms/common/api/GoogleApiClient;)Lcom/google/android/gms/common/api/OptionalPendingResult;"

对于谷歌位置(保险丝):

NoSuchMethodError: no non-static method "Lcom/google/android/gms/internal/zzary;.requestLocationUpdates(Lcom/google/android/gms/common/api/GoogleApiClient;Lcom/google/android/gms/location/LocationRequest;Lcom/google/android/gms/location/LocationListener;Landroid/os/Looper;)Lcom/google/android/gms/common/api/PendingResult;"

我也尝试过使用 google play 服务的预览版。没有运气。 知道如何解决这些错误吗?

** 编辑 1 ** 使用 cmets 中 John Douglas 的链接,以及来自 eugen 的答案中的链接,以及详细的诊断版本,在修复错误 2 小时后,proguard 文件终于可以在 Facebook 和 Google SDK 中正常工作了!

太棒了!

【问题讨论】:

标签: android xamarin facebook-android-sdk google-signin google-location-services


【解决方案1】:

这是来自 Facebook SDK for Android 4.23 的 proguard 配置:

-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();
}

来源:facebook-android-sdk on Github

这是来自 Google Play 服务 11.2 的 proguard 配置:

# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

# Needed for Parcelable/SafeParcelable classes & their creators to not get renamed, as they are
# found via reflection.
-keep class com.google.android.gms.common.internal.ReflectedParcelable
-keepnames class * implements com.google.android.gms.common.internal.ReflectedParcelable
-keepclassmembers class * implements android.os.Parcelable {
  public static final *** CREATOR;
}

# Keep the classes/members we need for client functionality.
-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <methods>;
}

# Keep the names of classes/members we need for client functionality.
-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

# Keep Dynamite API entry points
-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep @com.google.android.gms.common.util.DynamiteApi public class * {
  public <fields>;
  public <methods>;
}

# Needed when building against pre-Marshmallow SDK.
-dontwarn android.security.NetworkSecurityPolicy

# Needed when building against Marshmallow SDK.
-dontwarn android.app.Notification

# Protobuf has references not on the Android boot classpath
-dontwarn sun.misc.Unsafe
-dontwarn libcore.io.Memory

# Internal Google annotations for generating Proguard keep rules.
-dontwarn com.google.android.apps.common.proguard.UsedBy*

来源:com.google.android.gms:play-services-basement:11.2.0 来自 Google 存储库的工件

Set Up Google Play Services > 将 Google Play 服务添加到您的项目 > 其他中也描述了 Google Play 服务的 Proguard 设置。配置看起来与库 .aar 中的配置有点不同,请先尝试这个。

【讨论】:

  • 链接的Ty。但它不会编译有很多错误。不过这有点令人惊讶。
  • facebook-sdk proguard 是否未与项目 proguard 合并?所以我们必须手动扩展我们的proguard?
  • 我在我的 proguard 文件中添加了您的代码 facebook,但它没有帮助。仍然得到同样的异常
  • @batmaci 如果您使用 gradle 和 android studio,则无需为 facebook 或 google 手动设置 proguard。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多