如何在Android Studio中为Shell脚本设置路径?

问题描述

我想为我的android项目中的脚本设置脚本路径,而不使用严格的路径(/User/Documents/MyApp/tools/script.sh)和“工作目录” 。 / p>

我知道我可以使用“外部工具” ,但是此解决方案无效,因为所有项目开发人员都必须使用“外部工具”设置导入我的jar文件

我可以使用 $ ProjectFileDir $ 变量以某种方式写此路径吗?

enter image description here

解决方法

到目前为止,配置的路径值中有no direct way to use these variables

或者,您可以在gradle文件中创建一个task app/gradle来运行您的Shell脚本:

task runSS {
    doLast{
        exec {
            // chmod u+rwx demo.sh to make file executable
            executable "../demo.sh"
        }
    }
}

// other gradle tasks

请确保使用chmod u+rwx file_name将文件的权限更改为可执行文件。

现在运行文件:

enter image description here

输出:

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...