我不会讲英语的工作,但是...的Android gmaps犯规与minifyEnabled =真... apiKey被设置好的
我正在使用GMaps V2的Android应用程序。 所有的调试模式都很好,但是当我午餐释放应用程序时,地图代码不会执行!我确定发布apiKey设置良好(我将它设置在src/release/values/google_maps_api.xml中,并且apiKey没有限制),并且因为如果在发布版本中设置了minifyEnabled = false类型,它的工作!所以我认为这是使用ProGuard一个问题...
我尝试下一proguard的规则,但没有所有的组合...
-keep class com.google.** {*;}
-keep class com.hawk.angela.home.activities.MapFragment { *; }
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); }
-keepattributes InnerClasses
-dontoptimize
-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();
}
此外,在控制台不返回任何异常
映射初始化在F细分:
MapView mapView = (MapView) rootView.findViewById(R.id.mapView);
Bundle mapState = (savedInstanceState != null) ?
savedInstanceState.getBundle("mapState") :
null;
mapView.onCreate(mapState);
mapView.onResume(); // needed to get the map to display immediately
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
googleMap.setMaxZoomPreference(maxZoom);
// ...
}
});
任何人都可以帮助我吗?至少在哪里我必须找到问题...
谢谢!!
编辑: AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.enzonotario.app">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<!-- GCM permissions -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Pusher service -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme">
<meta-data
android:name="DATABASE"
android:value="app.db" />
<meta-data
android:name="VERSION"
android:value="2" />
<meta-data
android:name="QUERY_LOG"
android:value="false" />
<meta-data
android:name="DOMAIN_PACKAGE_NAME"
android:value="com.enzonotario.app" />
<meta-data
android:name="com.enzonotario.app.utils.GlideConfigurationModule"
android:value="GlideModule" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAqRP3ZQzc9gOhs3elhs7AL0qUo6wQOwZ8" />
<!-- Pusher's FCM listeners and services -->
<service android:name="com.pusher.android.notifications.fcm.FCMMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.pusher.android.notifications.fcm.FCMInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".SyncService"
android:exported="false" />
<receiver android:name=".gps.receivers.GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
// so many activities
</application>
</manifest>
google_maps_api.xml(释放)
<resources>
<!--
TODO: Before you release your application, you need a Google Maps API key.
To do this, you can either add your release key credentials to your existing
key, or create a new key.
Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.
Follow the directions here:
https://developers.google.com/maps/documentation/android/signup
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
AIzaSyAqRP3ZQzc9gOhs3elhs7AL0qUo6wQOwZ8
</string>
</resources>
你试过用mapfragment来代替吗? – meh