用于Android的Gradle跨平台构建脚本。

时间:2021-02-06 12:17:49

I have a build.gradle for my Android app and then some helper.gradle files for various sub tasks. Some of these helper tasks invoke shell scripts. Because this app has been in development on exclusively Linux and Mac machines, the shell scripts run fine.

我有一个构建。我的安卓应用程序,还有一些助手。用于各种子任务的渐变文件。其中一些帮助任务调用shell脚本。因为这个应用程序一直在开发Linux和Mac机器,所以shell脚本运行良好。

I've recently added a Windows development machine into the mix and the gradle build configuration is failing at calling the shell script.

我最近添加了一个Windows开发机器到混合版本中,而gradle构建配置在调用shell脚本时失败。

task helperTask1 << {
    exec {
        workingDir rootProject.getProjectDir()
        commandLine 'sh', './scripts/helperScript1.sh'
    }
}

At some point I'll get Cygwin up and running on the Windows machine, but what are my options for getting my app compiling?

有时我会让Cygwin在Windows机器上运行,但是我有什么办法让我的应用程序编译呢?

  1. Is there a way to effectively have a helperTask1_Linux and helperTask1_Windows tasks that get called on their respective platforms?
  2. 是否有一种方法可以有效地在各自的平台上调用helperTask1_Linux和helperTask1_Windows任务?
  3. Is there a more "gradle" way of calling shell scripts so that my gradle files are defining steps at a higher level?
  4. 是否有一种更“等级”的方式来调用shell脚本,以便我的等级文件在更高的级别上定义步骤?

1 个解决方案

#1


1  

Here is how I'm doing this:

我是这样做的:

  1. define a property 'ant.condition.os'. The value of the property depends of the OS.
  2. 定义一个属性“ant.condition.os”。属性的值取决于操作系统。
  3. use the value that property in a switch to call a windows or linux script.
  4. 使用开关中的属性值来调用windows或linux脚本。

ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix"   ) { os(family: "unix")    }

task myTask() {
    switch (ant.properties.os) {
        case 'windows':
            commandLine 'cmd', '/c', 'myscript.cmd'
            break;
        case 'unix':
            commandLine './myscript.sh'
            break;
    }
}

#1


1  

Here is how I'm doing this:

我是这样做的:

  1. define a property 'ant.condition.os'. The value of the property depends of the OS.
  2. 定义一个属性“ant.condition.os”。属性的值取决于操作系统。
  3. use the value that property in a switch to call a windows or linux script.
  4. 使用开关中的属性值来调用windows或linux脚本。

ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix"   ) { os(family: "unix")    }

task myTask() {
    switch (ant.properties.os) {
        case 'windows':
            commandLine 'cmd', '/c', 'myscript.cmd'
            break;
        case 'unix':
            commandLine './myscript.sh'
            break;
    }
}