Android Studio Gradle Pre Build步骤 [英] Android Studio Gradle Pre Build Step
问题描述
我只想在Gradle开始构建过程之前运行一个单独的应用程序(exe)。我的目标是让我的exe文件(已经写好)自动生成一个依赖文件,其中包含一个内部版本号,我将在UI中显示该版本号。以上所有内容都很简单,但我对Gradle几乎一无所知。
这个问题已被问到,但答案是简洁的Gradle片断,使用Gradle任务,以及不要解释太多。
我想在不同的项目中使用相同的exe,所以它需要一个命令参数来指定自动生成文件的位置; p>
buildnum.exe /someworkspace/someproject/somefolder/version.java
如何让它运行?我使用了一个典型的build.gradle脚本;
buildscript {
repositories {
jcenter()
}
依赖项{
classpath'com.android.tools.build:gradle:1.1.0'
}
}
所有项目{
repositories {
jcenter()
}
}
您可以使用 Exec 任务:
任务buildNum(类型:Exec,描述:'My Build num exe' ){
commandLine'buildnum.exe',
'/someworkspace/someproject/somefolder/version.java'
}
tasks.withType(JavaCompile){
compileTask - > compileTask.dependsOn buildNum
}
I would simply like to run a separate application (exe) prior to Gradle beginning the build progress. My goal is have my exe (already written) auto-gen a dependancy file containing a build number, which I display in the UI. All of the above is easy, but I know almost nothing of Gradle.
This question has been asked, but the answers are terse snippets of Gradle, using Gradle tasks, and do not explain much.
I want to use the same exe in different projects, so it takes a command argument to specify the location of the auto-gen file;
"buildnum.exe /someworkspace/someproject/somefolder/version.java"
How to I get this to run? I'm using a typical build.gradle script;
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
You can use an Exec task:
task buildNum(type: Exec, description: 'My Build num exe') {
commandLine 'buildnum.exe',
'/someworkspace/someproject/somefolder/version.java'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNum
}
这篇关于Android Studio Gradle Pre Build步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!