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

Google Maps示例在Android4.4.2 API19上构建成功却崩溃及Gradle错误求助

解决Google Maps示例在Android 4.4.2(API19)上崩溃+Gradle配置警告问题

遇到这种构建成功但旧设备运行崩溃,还伴随Gradle配置警告的情况,咱们分两步来搞定:

一、处理“Configuration 'compile'已过时”警告

Android Gradle Plugin从3.0版本开始就弃用了compile关键字,转而推荐使用implementation和api来管理依赖:

  • 如果你的依赖只在当前模块内部使用,直接把所有compile替换成implementation,比如:
    // 旧写法
    compile 'com.google.android.gms:play-services-maps:xx.x.x'
    // 新写法
    implementation 'com.google.android.gms:play-services-maps:xx.x.x'
    
  • 如果你的依赖需要暴露给其他模块(比如库模块),就用api替代compile。
  • 另外,更新插件后记得同步Gradle(点击AS右上角的“Sync Project with Gradle Files”按钮),确保配置生效。

二、解决Android 4.4.2设备/模拟器运行崩溃问题

这个问题主要是新版本Google Play Services与API19系统兼容性不匹配导致的,按以下步骤排查:

  1. 降低Play Services依赖版本
    新版本的Google Play Services(比如12.0+之后的部分版本)对旧系统的支持有所缩减,API19设备/模拟器上的Play Services版本往往无法匹配最新依赖。你可以把依赖降级到对API19友好的版本,比如11.8.0:

    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    implementation 'com.google.android.gms:play-services-location:11.8.0'
    

    这个版本完全支持API19,能避免因版本不兼容导致的崩溃。

  2. 检查Manifest配置
    在AndroidManifest.xml里确保添加了Play Services版本声明(旧版本Play Services在API19上必须):

    <application ...>
        <!-- 其他配置 -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
    

    同时,CurrentPlaceDetailsOnMap示例需要位置权限,记得在Manifest里声明:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    
  3. 模拟器特殊处理
    搭载Google APIs的API19 AVD往往自带的Play Services版本较低,无法更新到最新版,所以必须降低依赖版本才能正常运行。另外,确保创建AVD时选择了包含Google APIs的系统镜像,并且启动后没有提示Play Services需要更新(如果有,尝试在模拟器里手动更新,但API19可能无法更新,还是降级依赖更稳妥)。

  4. 查看崩溃日志定位问题
    如果按上面的步骤还是崩溃,打开AS的Logcat窗口,过滤Error级别日志,查看具体的崩溃栈信息:

    • 如果是GooglePlayServicesUtil: Google Play services out of date,说明依赖版本和设备上的Play Services版本不匹配,继续降低依赖版本;
    • 如果是ClassNotFoundException,检查是否有依赖缺失或者混淆配置问题(示例项目一般不会有混淆,但可以暂时关闭混淆测试)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:10:13