在Android SDK管理器中进行一些更新之后,我尝试使用签名的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警告,所有工作都完美无缺。怎么修理?
答案 0 :(得分:133)
虽然将此项添加到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;
}
答案 1 :(得分:40)
您需要像编译一样忽略,但您还需要保留该类,以便它可以在运行时找到它。
将这两行添加到proguard配置文件中:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
答案 2 :(得分:2)
我遇到了类似的问题,最终发现我更新了Google Play服务模块,但是我没有将模块重新添加到Android Studio的主模块中。添加它以解决我的问题。
答案 3 :(得分:2)
如果您使用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