android - 在gradle中执行shell脚本看不到echo输出

标签 android shell gradle

我正在使用这个问题Execute shell script in Gradle但是,作为引用,我不知道如何让它工作。

这是我的 gradle 文件:

...

task myPrebuildTask(type: Exec) {
    println "Hello world from gradle"
    commandLine 'sh', './myScript.sh'
}

build.dependsOn myPrebuildTask

我在 myScript.sh 中有这个

#!/bin/sh
echo "Hello world from the script file"

但是,每当我运行脚本 gradle assembleDebug 时,我只能看到“Hello world from gradle”,而看不到“Hello world from the script file”。

Yuchens-iMac:MyApplication yuchen$ gradle assembleDebug
Hello world from gradle
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
...

为什么?

最佳答案

我把这个放在一个新的 build.gradle

defaultTasks 'myPrebuildTask'

task myPrebuildTask(type: Exec){
    println "Hello world from gradle"
    commandLine 'sh', './myScript.sh'
}

运行 gradle -q 结果:

> gradle -q
Hello world from gradle
Hello world from the script file

很明显,该任务可以很好地打印命令输出。

您的情况可能会发生一些事情。当您调用 gradle assembleDebug 时,您设置的任务依赖性可能不足以触发您的自定义任务,或者,由于两条打印行实际上在不同的 gradle 阶段打印,因此第二行可能在您的日志中的其他地方- 你还没有发布完整的输出。

关于android - 在gradle中执行shell脚本看不到echo输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36803742/

相关文章:

java - MediaRecorder 停止时出错 : stop called in invalid state 4

android - 如何从 "declare-styleable"获取 double 值

linux - 根据列中的值有条件地复制表格数据文件的行

mysql - 在 while 循环中运行 mysql 命令

java - Gradle 插件依赖项存在但在构建期间未找到

java - 使用 Gradle 将前端构建的分发文件夹包含在 JAR 中

android - Android Studio 中应用级 gradle 文件中 "postprocessing" block 内的 'release' block 是什么?

java - 如何制作不同内容的重复通知

java - Android:SharedPreferences 编辑不起作用

linux - 将 3 个功能合并为一个