How to keep Google Maps in obfuscation?

别来无恙 提交于 2019-12-08 04:03:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!