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

Bre*_* P. 69 android proguard google-play-services

在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.
Run Code Online (Sandbox Code Playgroud)

如果设置-dontwarn com.google.android.gms.**编译没问题.但是在运行之后,我得到许多类似的报告错误(来自许多设备):

Caused by: android.view.InflateException: Binary XML file line #32: 
  Error inflating class com.google.android.gms.common.SignInButton
Run Code Online (Sandbox Code Playgroud)

在我的设备上一切都好.在更新之前,我没有ProGuard警告,所有工作都完美无缺.怎么修理?

tra*_*nte 136

虽然将此proguard-project.txt文件添加到文件中,但它会保留所有类.

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
Run Code Online (Sandbox Code Playgroud)

我更喜欢这个,这使得apk文件的大小更小:

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
Run Code Online (Sandbox Code Playgroud)

另请注意最新的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;
}
Run Code Online (Sandbox Code Playgroud)

  • 这仍然相关吗?play-services的proguard部分表示不需要特殊配置. (8认同)

Cod*_*sed 40

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

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

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
Run Code Online (Sandbox Code Playgroud)

  • 这太过分了. (8认同)