You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Google Map API的Android Demo应用启动崩溃求助

解决Android 9(API 28)上Google Map Demo启动崩溃的问题

这个崩溃的核心原因是Android 9(API 28)默认移除了Apache HTTP客户端库,而旧版本的Google Maps Dynamite组件依赖这个库,导致运行时找不到org.apache.http.ProtocolVersion类。

给你两个直接可行的解决办法:

方法一:在Manifest中声明保留Apache HTTP库支持

修改你的AndroidManifest.xml,在<application>标签内部添加以下代码:

<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

修改后的完整Manifest结构参考:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.googlemapdemo">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme">

    <!-- 添加Apache HTTP库兼容声明 -->
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

    <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" />
    <activity android:name=".MapsActivity" android:label="@string/title_activity_maps">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

方法二:升级Google Play服务依赖版本(推荐)

如果你的项目使用Gradle构建,建议升级Google Maps相关依赖到适配Android 9的新版本,新版本库已移除对Apache HTTP的依赖。在模块级build.gradle中更新依赖:

implementation 'com.google.android.gms:play-services-maps:17.0.1' // 可使用更高兼容版本

验证步骤

  • 清理项目:点击Android Studio菜单栏Build -> Clean Project
  • 重新构建:Build -> Rebuild Project
  • 重新运行应用到Mi A1设备

这样就能解决启动崩溃的问题了。

内容的提问来源于stack exchange,提问作者CanniZarro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:51:21