我在我的应用程序中使用 Google map 。我尝试在包含 map 的 fragment 中使用 MapView 和 SupportMapFragment。 出现的问题导致 Google map 在 map 初始化期间的“构建 APK”过程(在我测试过的所有设备中)之后崩溃,但是当从 Android Studio 运行时(使用运行)它按预期工作。这是堆栈跟踪(我在所有执行中得到的只是 AssertionError):
10-19 12:17:27.244 2256-2638/com.google.android.gms E/BaseAppContext: Tried to stop global GMSCore RequestQueue. This is likely unintended, so ignoring. 10-19 12:17:28.640 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null 10-19 12:17:29.537 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null 10-19 12:17:29.542 2256-2677/com.google.android.gms E/MDM: [142] rpv.a: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null} 10-19 12:17:30.112 1921-1921/com.google.android.gms.persistent E/ChimeraRcvrProxy: Can't find Chimera receiver impl class com.google.android.gms.auth.setup.devicesignals.LockScreenChimeraReceiver, dropping broadcast 10-19 12:17:31.602 2393-2501/com.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa112310 10-19 12:17:36.351 2776-2782/? E/art: Failed sending reply to debugger: Broken pipe 10-19 12:17:37.267 1269-1617/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 10-19 12:17:46.449 1269-1269/? E/EGL_emulation: tid 1269: eglCreateSyncKHR(1370): error 0x3004 (EGL_BAD_ATTRIBUTE) 10-19 12:17:47.050 2393-2501/com.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa112700 [ 10-19 12:17:47.094 2393: 2842 D/ ] HostConnection::get() New Host Connection established 0xb4050b90, tid 2842 10-19 12:17:47.222 1899-2797/com.android.inputmethod.latin E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae4428c0 10-19 12:17:48.704 2393-2769/com.app E/UncaughtException: java.lang.AssertionError at com.google.a.b.a.m$a.(Unknown Source) at com.google.a.b.a.m$19.a(Unknown Source) at com.google.a.f.a(Unknown Source) at com.google.a.b.a.b.a(Unknown Source) at com.google.a.f.a(Unknown Source) at com.google.a.b.a.i.a(Unknown Source) at com.google.a.b.a.i.a(Unknown Source) at com.google.a.b.a.i$1.(Unknown Source) at com.google.a.b.a.i.a(Unknown Source) at com.google.a.b.a.i.a(Unknown Source)
如此处所述,我在构建 gradle 中声明 API key : Google Maps Signed APK Android
我如何初始化 map 的代码示例:
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();
}
}
这是 fragment 布局:
<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”模式下不工作,可能会出现什么问题?
最佳答案
您已经找到了一种获取签名 APK 的 SHA-1 key 的正确方法。我认为,您应该检查开发人员控制台上的注册 key 并将两个 key 都放在那里:调试和发布。如果两者都存在,请查找包名称,确保它是 list 文件中定义的名称。然后等待几分钟,直到服务器配置您的 key 。希望能帮助到你。祝你好运
关于android - Google map 在 APK 构建执行期间崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40146238/