ProgramingTip

ProGuard : 참조 된 클래스 com.google.android.gms.R을 사용할 수 없습니다.

bestdevel 2020. 11. 3. 08:22
반응형

ProGuard : 참조 된 클래스 com.google.android.gms.R을 사용할 수 없습니다.


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 경고가 모두 완벽하게 작동합니다. 어떻게 해결합니까?


관리자 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

참고 URL : https://stackoverflow.com/questions/18646899/proguard-cant-find-referenced-class-com-google-android-gms-r

반응형