android 当我将其导出为 apk 时应用停止工作

android app stops working when i export it as an apk

我的代码中有一个地图片段。当我 运行 它使用 Android 工作室中的 'Run app' 时,它工作正常。但是,当我将其导出为已签名的 apk 时,相同的代码不会显示地图。我得到的只是一个空白屏幕,左下角有 google 徽标。

这是我的代码:

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            fm = getActivity().getSupportFragmentManager();
        } else {
            fm = getChildFragmentManager();
        }
        mMap =  ((SupportMapFragment) fm.findFragmentById(R.id.map)).getMap();

我的片段是:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/map"
tools:context="schoolbus.tracker.datavoice.schoolbusdrawer.MapsFragment"
android:name="com.google.android.gms.maps.SupportMapFragment" />

我也尝试了 getChildFragmentManager()、getSupportFragmentManager,但没有任何效果。

再一次,只有当我将其安装为已签名的 apk 时,该错误才会发生。否则地图 运行 很好。

谢谢。

用 application.After 中的发布键替换地图的调试 api 键,只有发布 apk 才会显示 google 地图。

我终于让它工作了,我改变了

 <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my-key" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my-key"/>

并添加:

 <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

现在工作正常