【发布时间】:2017-03-01 23:17:02
【问题描述】:
我在我的应用中使用 Google 地图。我尝试在包含地图的片段中使用 MapView 和 SupportMapFragment。 出现的问题导致谷歌地图在地图初始化期间“构建 APK”过程(在我测试过的所有设备中)后崩溃,但从 Android Studio 运行(使用运行)时,它按预期工作。这是堆栈跟踪(我在所有执行中得到的都是 AssertionError):
10-19 12:17:27.244 2256-2638/com.google.android.gms E/BaseAppContext:试图停止全局 GMSCore RequestQueue。这可能是无意的,所以忽略。 10-19 12:17:28.640 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter:蓝牙绑定器为空 10-19 12:17:29.537 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter:蓝牙绑定器为空 10-19 12:17:29.542 2256-2677/com.google.android.gms E/MDM:[142] rpv.a:无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE,分辨率=null,消息=空} 10-19 12:17:30.112 1921-1921/com.google.android.gms.persistent E/ChimeraRcvrProxy:找不到 Chimera 接收器 impl 类 com.google.android.gms.auth.setup.devicesignals.LockScreenChimeraReceiver,丢弃播送 10-19 12:17:31.602 2393-2501/com.app E/Surface:getSlotFromBufferLocked:未知缓冲区:0xaa112310 10-19 12:17:36.351 2776-2782/? E/art:向调试器发送回复失败:管道损坏 10-19 12:17:37.267 1269-1617/? E/SurfaceFlinger: ro.sf.lcd_density 必须定义为构建属性 10-19 12:17:46.449 1269-1269/? E/EGL_emulation: tid 1269: eglCreateSyncKHR(1370): 错误 0x3004 (EGL_BAD_ATTRIBUTE) 10-19 12:17:47.050 2393-2501/com.app E/Surface:getSlotFromBufferLocked:未知缓冲区:0xaa112700 [ 10-19 12:17:47.094 2393:2842 D/ ] HostConnection::get() 新主机连接建立 0xb4050b90, tid 2842 10-19 12:17:47.222 1899-2797/com.android.inputmethod.latin E/Surface:getSlotFromBufferLocked:未知缓冲区:0xae4428c0 10-19 12:17:48.704 2393-2769/com.app E/UncaughtException: java.lang.AssertionError 在 com.google.a.b.a.m$a.(未知来源) 在 com.google.a.b.a.m$19.a(未知来源) 在 com.google.a.f.a(未知来源) 在 com.google.a.b.a.b.a(未知来源) 在 com.google.a.f.a(未知来源) 在 com.google.a.b.a.i.a(未知来源) 在 com.google.a.b.a.i.a(未知来源) 在 com.google.a.b.a.i$1.(未知来源) 在 com.google.a.b.a.i.a(未知来源) 在 com.google.a.b.a.i.a(未知来源)
如此处所述,我在 build gradle 中声明 API 密钥: Google Maps Signed APK Android
我如何初始化地图的代码示例:
public class MainMapFragment extends BaseFragment implements{...
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onCreate()");
super.onCreate(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
_mapFragment = (SupportMapFragment) fm.findFragmentByTag(Consts.TAGS.UTIL_MAP);
if (_mapFragment == null) {
Log.d(Consts.TAGS.FRAG_MAIN_MAP,"mapFragment is null. creating new map...");
_mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map_container, _mapFragment).commit();
_mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onMapReady()");
_map = googleMap;
//_map.setInfoWindowAdapter(this);
_map.setInfoWindowAdapter(new CDInfoWindowAdapter(getActivity(),_markersPos));
_map.setOnInfoWindowClickListener(this);
_map.setPadding(120, 120, 170, 200);
MapsInitializer.initialize(getActivity());
initilizeMap();
}
}
这是片段布局:
<RelativeLayout tools:context=".MainMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_container"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--<fragment-->
<!--android:id="@+id/map"-->
<!--android:name="com.google.android.gms.maps.SupportMapFragment"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--/>-->
<!--<com.google.android.gms.maps.MapView-->
<!--xmlns:android="http://schemas.android.com/apk/res/android"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:id="@+id/map_view"-->
<!--/>
-->
</RelativeLayout>
如果代码在运行模式下工作但在“构建 APK”模式下不工作,会出现什么问题?
【问题讨论】:
-
您是否在清单中添加了 google maps 键??
-
你的目标 API 是什么?你能告诉我们initializeMap吗?
标签: android google-maps android-gradle-plugin assert debug-build