【发布时间】:2022-02-03 11:28:36
【问题描述】:
我正在使用 secrets-gradle-plugin 读取我放入 local.properties 中的 API 密钥。
我已将此代码添加到根build.gradle
buildscript {
dependencies {
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
}
}
对于应用程序build.gradle
plugins {
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}
android {
compileSdk 31
...
}
这是我的local.properties
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#
sdk.dir=/Users/xxx/Library/Android/sdk
apiKey=YOUR_API_KEY
然后,当我尝试从任何类/应用程序访问它时,BuildConfig.apiKey 不存在。我在这里错过任何步骤吗?尝试了几个小时,但没有找到任何方法来完成这项工作。
【问题讨论】:
-
@HashT 找到了从您的链接中获取属性值的方法。非常感谢。
标签: android gradle google-api api-key secret-key