72

After some updates in Android SDK manager I try make signed apk and get this:

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. 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. How it fix?

JJD
  • 50,076
  • 60
  • 203
  • 339
Bred P.
  • 786
  • 1
  • 5
  • 8
  • Possible duplicate of [proguard hell - can't find referenced class](https://stackoverflow.com/questions/6974231/proguard-hell-cant-find-referenced-class) – Yuliia Ashomok Oct 02 '18 at 15:06

4 Answers4

141

Although adding this to proguard-project.txt file works, it keeps all classes.

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

I prefer this, which makes apk file size much smaller:

-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

-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;
}
trante
  • 33,518
  • 47
  • 192
  • 272
  • 1
    You helped me to save a few Mb's with your second suggestion. Thanks! – palvarez89 Jan 03 '16 at 16:39
  • 10
    is this still relevant? the play-services' proguard section says no special configuration needed. – AsafK Feb 22 '18 at 15:33
  • I've removed those 2 lines, and generation of APK completes without any problem. Firebase Analytics & Invites working fine, haven't tried anything else yet. – Mark Apr 10 '18 at 07:54
  • I still keep getting crash reports `Didn't find class "com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver" on path DexPathList` on Xamarin, So i will implement these lines and see if it works for me – Pierre Nov 12 '18 at 06:09
42

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:

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
glenneroo
  • 1,908
  • 5
  • 30
  • 49
Codeversed
  • 9,287
  • 3
  • 43
  • 42
  • 9
    This keeps far too much. – rds Sep 26 '16 at 11:20
  • @rds Obviously it uses a wildcard and you can pick what you want with providing more specific class naming. When you start cutting out GMS classes you can run into a lot of unexpected trouble with user crashes. – Codeversed Sep 26 '16 at 14:42
  • should we use keep with dontwarn in general for any warning which we want to ignore? – Emil Nov 27 '16 at 04:52
2

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. Adding that back in resolved my issues.

Cassie
  • 5,223
  • 3
  • 22
  • 34
2

If you use proguard, you need to keep some GMS (Google Play Services) classes. Hopefully they are annotated with @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
rds
  • 26,253
  • 19
  • 107
  • 134