繁体   English   中英

ProGuard:找不到引用的类com.google.android.gms.R

[英]ProGuard: can't find referenced class com.google.android.gms.R

在Android SDK Manager中进行一些更新后,我尝试使签名的apk并获得此信息:

ProGuard: [] Warning: com.google.android.gms.auth.GoogleAuthUtil: 
  can't find referenced class com.google.android.gms.R
ProGuard: [] Warning: com.google.android.gms.auth.GoogleAuthUtil: 
  can't find referenced class com.google.android.gms.R$string
...
etc.

如果设置了-dontwarn com.google.android.gms.**编译正常。 但是运行后,我收到许多这样的错误报告(来自许多设备):

Caused by: android.view.InflateException: Binary XML file line #32: 
  Error inflating class com.google.android.gms.common.SignInButton

在我的设备上一切正常。 在更新之前,我没有ProGuard警告,并且一切正常。 如何解决?

尽管将其添加到proguard-project.txt文件是proguard-project.txt ,但它保留所有类。

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

我更喜欢这样做,它使apk文件的大小小得多:

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

还要在此处记录最新的Google Play Proguard通知: http : //developer.android.com/google/play-services/setup.html#Proguard

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

您需要像编译时一样忽略它,但是还需要保留该类,以便它可以在运行时找到它。

将这两行添加到您的proguard配置文件中:

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

我遇到了类似的问题,最终发现我已经更新了Google Play服务模块,但是没有将模块重新添加到Android Studio的主模块中。 添加回去解决了我的问题。

如果使用proguard,则需要保留一些GMS(Google Play服务)类。 希望它们使用@com.google.android.gms.common.annotation.KeepName进行注释。

# Proguard config for project using GMS

-keepnames @com.google.android.gms.common.annotation.KeepName class
    com.google.android.gms.**,
    com.google.ads.**

-keepclassmembernames class
    com.google.android.gms.**,
    com.google.ads.** {
    @com.google.android.gms.common.annotation.KeepName *;
}

# Called by introspection
-keep class
    com.google.android.gms.**,
    com.google.ads.**
    extends java.util.ListResourceBundle {
    protected java.lang.Object[][] getContents();
}


# This keeps the class name as well as the creator field, because the
# "safe parcelable" can require them during unmarshalling.
-keepnames class
    com.google.android.gms.**,
    com.google.ads.**
    implements android.os.Parcelable {
    public static final ** CREATOR;
}

# com.google.android.gms.auth.api.signin.SignInApiOptions$Builder
# references these classes but no implementation is provided.
-dontnote com.facebook.Session
-dontnote com.facebook.FacebookSdk
-keepnames class com.facebook.Session {}
-keepnames class com.facebook.FacebookSdk {}

# android.app.Notification.setLatestEventInfo() was removed in
# Marsmallow, but is still referenced (safely)
-dontwarn com.google.android.gms.common.GooglePlayServicesUtil

暂无
暂无

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

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