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

Android Studio中build.gradle.kts引入Google Maps报错求助

解决build.gradle.kts中Google Maps依赖报错问题

你遇到的错误是因为build.gradle.kts采用Kotlin DSL语法,而你写的是Groovy DSL的依赖格式,两者语法规则不兼容,才会触发"Unexpected tokens"和"Variable 'implementation' must be initialized"报错。

正确的Kotlin DSL依赖写法如下,必须把依赖放在dependencies代码块内,且implementation是函数调用,参数用括号包裹:

dependencies {
    implementation("com.google.android.gms:play-services-maps:18.1.0")
    implementation("com.google.android.gms:play-services-location:20.0.0")
}

修改完成后,点击Android Studio右上角的「Sync Project with Gradle Files」按钮同步项目,或者在终端执行./gradlew sync命令,确保依赖配置生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 06:00:54