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

升级AGP 8.3.0-alpha06后构建报错:No value passed for parameter 'providers'

问题背景

将Android Studio升级至Iguana | 2023.2.1 Canary 6(后续升级到Canary 7),同时把AGP版本升级到8.3.0-alpha06后,项目构建在读取local.properties中的API密钥时失败。

环境信息

Android Studio Iguana | 2023.2.1 Canary 6
Build #AI-232.9921.47.2321.10875067, built on September 28, 2023
Runtime version: 17.0.8+0-17.0.8b1000.22-10799086 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.6.1
GC: G1 Young Generation, G1 Old Generation
Memory: 5120M
Cores: 12
Metal Rendering is ON
Registry:
    external.system.auto.import.disabled=true
    debugger.new.tool.window.layout=true
    ide.text.editor.with.preview.show.floating.toolbar=false
    ide.instant.shutdown=false
    ide.experimental.ui=true
    ide.images.show.chessboard=true

Non-Bundled Plugins:
    com.github.rmehri01.onenord (0.0.7)
    com.arcticicestudio.nord.jetbrains (0.13.0)

报错代码及信息

原代码:

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

val googleApiKey: String = gradleLocalProperties(rootDir).getProperty("GOOGLE_API_KEY")
val googleCrashReportingApiKey: String = gradleLocalProperties(rootDir).getProperty("GOOGLE_CRASH_REPORTING_API_KEY")

构建错误:

* What went wrong:
Script compilation errors:

  Line 16: val googleApiKey: String = gradleLocalProperties(rootDir).getProperty("GOOGLE_API_KEY")
                                                            ^ No value passed for parameter 'providers'

  Line 17: val googleCrashReportingApiKey: String = gradleLocalProperties(rootDir).getProperty("GOOGLE_CRASH_REPORTING_API_KEY")
                                                                          ^ No value passed for parameter 'providers'

2 errors

根本原因

并非rootDir为空,核心原因是:

  1. gradleLocalProperties是AGP的内部未公开API,不属于官方推荐的公共接口,AGP团队在版本迭代时可随意修改其方法签名。
  2. 在AGP 8.3 alpha版本中,该方法签名发生变化——原本仅需传入rootDir参数,现在要求额外传入ProviderFactory类型的providers参数,导致旧代码因参数缺失编译失败。

解决方法

放弃使用AGP内部API,改用标准的Java Properties类读取local.properties文件,示例代码如下:

val properties = Properties().apply { 
    load(FileInputStream(File(rootProject.rootDir, "local.properties"))) 
}

val googleApiKey: String = properties.getProperty("GOOGLE_API_KEY")
val googleCrashReportingApiKey: String = properties.getProperty("GOOGLE_CRASH_REPORTING_API_KEY")

更规范的Gradle写法(避免直接IO操作风险)

val localPropertiesFile = rootProject.file("local.properties")
val properties = java.util.Properties().apply {
    if (localPropertiesFile.exists()) {
        load(localPropertiesFile.inputStream())
    }
}

val googleApiKey = properties.getProperty("GOOGLE_API_KEY")
val googleCrashReportingApiKey = properties.getProperty("GOOGLE_CRASH_REPORTING_API_KEY")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 13:33:01