如何在 Gradle Kotlin DSL 中从环境添加 resValue?

How to add a resValue from the environment in Gradle Kotlin DSL?

我正在尝试使用 Gradle Kotlin DSL 通过 resValue 在我的机器上的环境中添加资源值。我的问题是所需变量 BearerToken 未解析。该值存储在我的 Mac 的 Users/myuser/.gradle/gradle.properties 文件中。

在常规的 Kotlin DSL 中,下面的代码工作得很好

resValue 'string', "bearer_token", BearerToken

我正在转换为 Gradle Kotlin DSL,并具有以下内容

resValue("string", "bearer_token", BearerToken)

Gradle 同步失败并报告 BearerToken 未解决。我无法使用任何其他 API。

我试过使用 System.getenv("BearerToken") 也没有用。

有人知道问题出在哪里吗?

我还没试过这个。但是属性最终出现在 project.properties 映射中。 所以不要 System.getenv 试试:project.properties.get("BearerToken")

我只是尝试

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

gradleLocalProperties(rootDir).getProperty([KEY]) ?:""