8

I am developing an app that uses google maps. The app works fine up until I Export the signed app package .After the code has been obfuscated the maps are no longer loaded. I am pretty new to ProGuard,I've tried modifying proguard.cfg but soo far nothing has worked. Here are some of the different things that i've tried:

-libraryjars C:/Program Files/Android/android-sdk/add-ons/addon-google_apis-google_inc_-10/libs/maps.jar

-keep class android.location.** { *; }

-keepnames class com.google.android.maps.** {*;}
-keep public class com.google.android.maps.** {*;}

-dontwarn com.google.android.maps.GeoPoint
-dontwarn com.google.android.maps.MapActivity
-dontwarn com.google.android.maps.MapView
-dontwarn com.google.android.maps.MapController 
-dontwarn com.google.android.maps.Overlay

Thanks

2
  • 1
    Have you got the Maps API key with the signature used while exporting? it might not be an issue with obfuscation. It might be issue with the Map API key.
    – Karthik
    Commented Feb 6, 2012 at 10:14
  • Yes you were right I was using my old debug key. Thank you soo much. Commented Feb 6, 2012 at 11:42

5 Answers 5

18

Edit: For Google Maps For Android V2 Specifically:

Just in case anyone sees this and has a similar issue - I was getting a Parcelable RuntimeException when I tried to view a second map (as in, Activity A had a map instance, then moving to Activity B, another instance with different params), pointing to what i was assuming was an obfuscated class name in the google package.

after i added

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

to my proguard-project.txt everything seemed to keep working as normal

2
  • The accepted answer didn't work, but is still a good troubleshooting step. Keeping the google maps package deobfuscated is the way to go, only added around 1mb to my build so is worth the trade-off for now.
    – lasec0203
    Commented Apr 28, 2021 at 20:52
  • For my case it was BadParcelableException with error: ClassNotFoundException when unmarshalling: com.google.android.gms.maps.StreetViewPanoramaOptions when I navigate to a different Activity from the map instance Activity, and then go back to it. Adding this proguard rule fixes the issue. Thanks!
    – Bruce
    Commented Dec 22, 2022 at 14:25
10

It is most likely issue with the Maps API Key. You should generate the Key with the signature used while exporting the app and use it in your map view.
Its unlikely that Obfuscation using ProGuard will affect the map rendering.

1
  • Go to google console, and then edit that key. add a new signature (eg. 4B:22:12:....:12) to that API. New signature you can find from logcat filtering with your app's package name
    – Dewsworld
    Commented Oct 13, 2019 at 15:49
0

It might help:

-optimizations !code/simplification/variable

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.app.Fragment

# The Maps API uses custom Parcelables.
# Use this rule (which is slightly broader than the standard recommended one)
# to avoid obfuscating them.

-keepclassmembers class * implements android.os.Parcelable {
    static *** CREATOR;
}

# The Maps API uses serialization.

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

Source: https://github.com/googlemaps/android-samples/blob/master/ApiDemos/app/proguard-rules.pro

0

I've had a similar issue using the Google Maps Roads API - it didn't work in obfuscated code. Turns out, the API library uses reflection under the hood, so the solution was to add

-keep class com.google.maps.** { *; }

to proguard-rules.pro.

(Adding this answer here specifically, because this question came up as the most related when I was searching for a solution to my issue, and finding the answer here would've saved me a couple hours of further searching.)

0

this is better

-keep class * implements com.google.android.gms.maps { *; }
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.