[英]Create gradle file programmatically from build.gradle file
I have an assignment task so I have downloaded the project to implement the task but found in readme file我有一个分配任务,所以我下载了项目来实施任务,但在自述文件中找到
"you still need to register for an API key and add it to
app/local.gradle
- seelocal.gradle.example
for details."“您仍然需要注册API 密钥并将其添加到
app/local.gradle
- 有关详细信息,请参阅local.gradle.example
。”
and found inside并在里面找到
local.gradle.example
local.gradle.example
android {
defaultConfig {
buildConfigField "String", "API_KEY", "\"api key\""
}
}
and the和
app/local.gradle
应用程序/本地.gradle
was not there不在那里
and inside build.gradle file I have found在 build.gradle 文件中我发现
if (!file("local.gradle").exists()) {
exec {
commandLine "sh"
args = ["-c", "cp local.gradle.example local.gradle"]
}
}
apply from: "local.gradle"
when I tried to run the project it gives an error says当我尝试运行该项目时,它给出了一个错误说
java.io.IOException: Cannot run program "sh" (in directory "E:\android-assignment-main\app"): CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program "sh" (in directory "E:\android-assignment-main\app"): CreateProcess error=2, 系统找不到指定的文件
so how to first create local.gradle file?那么如何首先创建 local.gradle 文件? from programmatically from build.gradle
从 build.gradle 以编程方式
It seems the issue is that you are on Windows and try to run a shell script, which will not work like this.似乎问题在于您在 Windows 上并尝试运行 shell 脚本,但它不会像这样工作。
I would suggest to use Gradle's Copy task to do this:我建议使用 Gradle 的Copy 任务来执行此操作:
task copyLocalGradle(type: Copy) {
if (!file("app/local.gradle").exists()) {
from 'local.gradle.example'
into 'app'
rename 'local.gradle.example', "local.gradle"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.