简体   繁体   English

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

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

After some updates in Android SDK manager I try make signed apk and get this: 在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.

If set -dontwarn com.google.android.gms.** compiling is OK. 如果设置了-dontwarn com.google.android.gms.**编译正常。 But after run I get error many reports like this (from many devices): 但是运行后,我收到许多这样的错误报告(来自许多设备):

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

On my devices all ok. 在我的设备上一切正常。 Before update I have not ProGuard warnings and all work perfectly. 在更新之前,我没有ProGuard警告,并且一切正常。 How it fix? 如何解决?

Although adding this to proguard-project.txt file works, it keeps all classes. 尽管将其添加到proguard-project.txt文件是proguard-project.txt ,但它保留所有类。

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

I prefer this, which makes apk file size much smaller: 我更喜欢这样做,它使apk文件的大小小得多:

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

Also note up to date Google Play Proguard notification here: http://developer.android.com/google/play-services/setup.html#Proguard 还要在此处记录最新的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;
}

You need to ignore like you are compiling but you also need to keep the class so it can find it during runtime. 您需要像编译时一样忽略它,但是还需要保留该类,以便它可以在运行时找到它。

Add these two lines to your proguard configuration file: 将这两行添加到您的proguard配置文件中:

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

I came across a similar issue and eventually discovered that I had updated the Google Play Services module however I hadn't re-added the module to my main module in Android Studio. 我遇到了类似的问题,最终发现我已经更新了Google Play服务模块,但是没有将模块重新添加到Android Studio的主模块中。 Adding that back in resolved my issues. 添加回去解决了我的问题。

If you use proguard, you need to keep some GMS (Google Play Services) classes. 如果使用proguard,则需要保留一些GMS(Google Play服务)类。 Hopefully they are annotated with @com.google.android.gms.common.annotation.KeepName . 希望它们使用@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.

相关问题 找不到符号导入 com.google.android.gms.R - cannot find symbol import com.google.android.gms.R Proguard - 找不到[com / google / android / gms / d / kl]的常见超类 - Proguard - Can't find common super class of [com/google/android/gms/d/kl] com.google.android.gms.internal.zzhu:找不到引用的类android.security.NetworkSecurityPolicy - com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy 错误Android com.google.android.gms.r $ styleable错误 - Error Android com.google.android.gms.r$styleable error NoClassDefFoundError:com.google.android.gms.R $ styleable - NoClassDefFoundError: com.google.android.gms.R$styleable 无法加载“可设置样式的com.google.android.gms.r” - Failed to load “com.google.android.gms.r styleable” Android ProGuard警告-找不到引用的类“ com.zhihu.matisse.R $ plurals” - Android ProGuard warning — can't find referenced class “com.zhihu.matisse.R$plurals” Android ProGuard:找不到引用的类 - Android ProGuard: can't find referenced class Proguard android找不到引用的类 - Proguard android can't find referenced class Android Google Maps v2:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Android Google Maps v2: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM