Gradle 构建在根文件夹中找不到 apikey.properties 文件
Gradle build won't find the apikey.properties file in root folder
我正在尝试添加一个 apikey.properties 文件,其中包含一些客户端 ID 和机密以获取令牌。
我 运行 在尝试了此线程中 Victory 给出的示例后遇到的问题:
我 运行 在尝试构建时遇到了这个问题:
Build file 'C:\app root\app\build.gradle' line: 7
A problem occurred evaluating project ':app'.
> C:\app root\apikey.properties (The system cannot find the file specified)
build.gradle(:app):
...
def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
...
...
// should correspond to key/value pairs inside the file
buildConfigField("String", "scope", apikeyProperties['scope'])
buildConfigField("String", "client_id", apikeyProperties['client_id'])
buildConfigField("String", "client_secret", apikeyProperties['client_secret'])
buildConfigField("String", "grant_type", apikeyProperties['grant_type'])
...
apikey.properties 文件:
scope=xxx
client_id=xxx
client_secret=xxx
grant_type=xxx
不确定我在这里做错了什么,感谢任何帮助!
试试这个。
gradle 文件..
Properties properties = new Properties()
if (rootProject.file("apikey.properties").exists()) {
properties.load(rootProject.file("apikey.properties").newDataInputStream())
}
def mapsApiKey = properties.getProperty("MAPS_API_KEY")
defaultConfig {
buildConfigField("String", "MAPS_API_KEY", "\"$mapsApiKey\"")
}
apikey.properties..
MAPS_API_KEY=AIzqwdqwdqwdqwdqwdqdww
我正在尝试添加一个 apikey.properties 文件,其中包含一些客户端 ID 和机密以获取令牌。
我 运行 在尝试了此线程中 Victory 给出的示例后遇到的问题:
我 运行 在尝试构建时遇到了这个问题:
Build file 'C:\app root\app\build.gradle' line: 7
A problem occurred evaluating project ':app'.
> C:\app root\apikey.properties (The system cannot find the file specified)
build.gradle(:app):
...
def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
...
...
// should correspond to key/value pairs inside the file
buildConfigField("String", "scope", apikeyProperties['scope'])
buildConfigField("String", "client_id", apikeyProperties['client_id'])
buildConfigField("String", "client_secret", apikeyProperties['client_secret'])
buildConfigField("String", "grant_type", apikeyProperties['grant_type'])
...
apikey.properties 文件:
scope=xxx
client_id=xxx
client_secret=xxx
grant_type=xxx
不确定我在这里做错了什么,感谢任何帮助!
试试这个。
gradle 文件..
Properties properties = new Properties()
if (rootProject.file("apikey.properties").exists()) {
properties.load(rootProject.file("apikey.properties").newDataInputStream())
}
def mapsApiKey = properties.getProperty("MAPS_API_KEY")
defaultConfig {
buildConfigField("String", "MAPS_API_KEY", "\"$mapsApiKey\"")
}
apikey.properties..
MAPS_API_KEY=AIzqwdqwdqwdqwdqwdqdww