13

After upgrading to Google Play services v23, I see this message when trying to export signed application in Eclipse:

Proguard returned with error code 1. See console
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller$SessionInfo
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced class android.content.pm.PackageInstaller$SessionInfo
Warning: com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced method 'android.content.pm.PackageInstaller getPackageInstaller()' in class android.content.pm.PackageManager
Warning: com.google.android.gms.internal.zzif: can't find referenced method 'void setMixedContentMode(int)' in class android.webkit.WebSettings
      You should check if you need to specify additional program jars.
Warning: there were 4 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars').
Warning: there were 2 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile them and try again.
         Alternatively, you may have to specify the option 
         '-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:321)
    at proguard.ProGuard.initialize(ProGuard.java:211)
    at proguard.ProGuard.execute(ProGuard.java:86)
    at proguard.ProGuard.main(ProGuard.java:492)

I added this, as specified in documentation

-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;
}

and tried adding

-keep class android.content.pm.PackageInstaller.**

to proguard-project.txt, but this didnt help.

What am I missing?

A.G.
  • 2,037
  • 4
  • 29
  • 40

4 Answers4

45

hey i had the exact same error i fixed it by adding :

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

to my proguard.cfg

Lary Ciminera
  • 1,270
  • 8
  • 15
  • 3
    This solution helped me, but the second suggestion in http://stackoverflow.com/questions/18646899/proguard-cant-find-referenced-class-com-google-android-gms-r/24109609#24109609 makes apk file size much smaller. – palvarez89 Jan 03 '16 at 16:42
  • I have tried the same but now build is running and running. Android studio is not generating apk. Can anyone help? – AndiGeeky May 03 '17 at 11:06
  • Documentation says that there is no need to add proguard rules manually for this – Rasel Feb 27 '18 at 09:52
11

I have the same problem, but using Android Studio. Based on Lary Ciminera's solution, I added

-dontwarn com.google.android.gms.**

to proguard-project.txt.

Peter McLennan
  • 371
  • 4
  • 11
6

I fixed it by adding this to proguard-project.txt:

-keep class android.content.pm.PackageInstaller
-keep class android.content.pm.PackageInstaller$SessionInfo
-keep class android.content.pm.PackageManager

-dontwarn android.content.pm.PackageInstaller
-dontwarn android.content.pm.PackageInstaller$SessionInfo
-dontwarn android.content.pm.PackageManager

-keep class android.webkit.WebSettings
-dontwarn android.webkit.WebSettings
A.G.
  • 2,037
  • 4
  • 29
  • 40
2

Upgrading your target SDK version to at least 21 should fix this problem. PackageInstaller and the associated classes were added in API version 21: https://developer.android.com/reference/android/content/pm/PackageInstaller.html

joeblubaugh
  • 1,127
  • 7
  • 10
  • Doesn't that prevent the app for being used on device that have an Android lower than 5.0 ? because that's like 3% of all device. – Lary Ciminera May 19 '15 at 09:07
  • @LaryCiminera no, the target is different from the minSdkVersion; the targetSdk might trigger compability modes. you should set the targetSdk to the newest one you have the app with. – stefs May 19 '15 at 16:26