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

Android应用接受位置权限时崩溃,求助排查IncompatibleClassChangeError

问题分析

崩溃根源是java.lang.IncompatibleClassChangeError:代码期望com.google.android.gms.location.SettingsClient是类,但实际它是一个接口。这是因为Google Play Services定位库版本更新后,SettingsClient从类改为了接口,而你使用的第三方定位库(transistorsoft的TSLocationManager)依赖的旧版API与当前引入的新版库不兼容。

解决方案
  • 统一Google Play Services定位库版本
    在Module级别的build.gradle中,强制所有依赖使用相同版本的play-services-location,示例:

    dependencies {
        // 替换为当前稳定版,比如21.0.1
        implementation 'com.google.android.gms:play-services-location:21.0.1'
    }
    // 或用依赖解析规则统一版本
    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-location:21.0.1'
        }
    }
    
  • 更新transistorsoft定位库版本
    你使用的TSLocationManager版本过旧,无法兼容新版play-services-location。升级该库到支持当前play-services-location版本的最新版。

  • 排查定位插件冲突
    同时使用Location和geolocator插件可能引发依赖冲突,两个插件可能引入了不同版本的play-services-location。可以移除其中一个插件,或者在依赖中排除冲突模块,示例:

    // 假设geolocator引入冲突版本,排除它
    implementation('com.example.geolocator:library:x.x.x') {
        exclude group: 'com.google.android.gms', module: 'play-services-location'
    }
    
  • 清理重建项目
    执行命令清除缓存并重新构建:

    ./gradlew clean
    ./gradlew assembleDebug
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 15:13:08