问题
I have implemented Google Maps (Google API) in my application. So I added ProGuard file inside my application. After adding the Proguard file, the map is not opening, and showing a white blank screen.
This is my Proguard code:
-keep class * implements com.google.android.gms.maps { *; }
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
I have tried this, but it's not working.
回答1:
The Google Maps API
uses some other stuff as well which can cause problems during obfuscation, like custom Parcelables and serialization. These rules should work:
-keepclassmembers class * implements android.os.Parcelable {
static *** CREATOR;
}
-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
According to @Fakher in the comments:
Also note that your API key needs to be correct, Google only show you a visible Map if you have requested an API key and added it in your application.
来源:https://stackoverflow.com/questions/46908864/how-to-keep-google-maps-in-obfuscation