Android ProGuard issues with Google API libraries

This will be a short post. So, I have working with the Google API java library for Android and time has come to package the app for release and boom! ProGuard problems! First I had an issue with MinMaxPriorityQueue. When I tried to “Export Signed Application Package”, ProGuard would fail with a warning about this class. To get past this, you need to tell ProGuard not to warn you about it. Add this to your proguard.cfg:

-dontwarn com.google.common.collect.MinMaxPriorityQueue

Next, I had a problem with the JSON response from the API. It would complain about how there isn’t a publicly available constructor in a package (ex: com.google.api.a.a.a.d or something like that). Your error may not be the same but it is more or less the same problem as mine (or anyone else using Google API libraries for Android). So you need to tell ProGuard to keep certain API classes from obfuscation:

-keep class com.google.api<full package name of whatever library you are using>

I suggest also adding any other package (or individual classes) that you have declared in your application that is designated as a model for API responses. One last thing to note is, if your ProGuard config file doesn’t already have it, you should also add this:

-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}

This would have already been added for you if you used the “android update project -p <your project>” in your command line (or Terminal) or if you have been using the latest Android tools.

Advertisements

16 thoughts on “Android ProGuard issues with Google API libraries

  1. I have added the -keepclassmembers class * {
    @com.google.api.client.util.Key ;
    }
    but still not working when i change the location in my application.

    Like

  2. Can you email me the errors? Your statement is too generic for me to tell you what might be wrong with your proguard setup. Actually stating what errors you receive will help me help you.

    Like

    • Paste your full proguard config, the actual error stack trace. That way I can see what is wrong and what is missing in your proguard config to recommend adding something to it.

      Like

  3. No i haven’t found any exception or problem while exporting a release build.did u find problem in the code ?.which i sent to u.

    Like

  4. it is showing “Caused by: java.lang.InstantiationException:” com.ideafarms.android.dealchaat.models.Place$Geometry

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s