[英]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.