【问题标题】:Google Maps crash during APK build executionAPK 构建执行期间 Google 地图崩溃
【发布时间】: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


【解决方案1】:

您已经找到了一种正确的方法来获取 SHA-1 密钥以用于单点 APK。我认为,您应该在开发人员控制台上检查已注册的密钥并将两个密钥都放在那里:调试和发布。如果两者都在那里查找包名称,请确保它是清单文件中定义的内容。然后等待几分钟,直到服务器配置好您的密钥。希望能帮助到你。祝你好运

【讨论】:

    【解决方案2】:

    您的 apk 的地图密钥似乎有问题。您是否为您的包生成了一个新密钥以及您用于构建 apk 的密钥?

    【讨论】:

    • 您做对了,但该应用程序尚未准备好投入生产。因此,我更喜欢我在这里添加的答案。我认为在 apk 的调试构建过程中,为什么 google 更愿意使用不同的 API 密钥(用于生产的密钥),这有点令人费解。
    【解决方案3】:

    为了纠正它,我做了什么(因为应用程序尚未准备好投入生产,并且 Google API 和 SDK 尝试使用与 apk 构建类型无关的密钥)正在配置 gradle build 以像我一样工作预计它会工作:

        buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            **debuggable true**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            resValue "string", "google_maps_api_key", "***************"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 2017-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多