在 android gradle 中执行 shell 脚本

Execute shell script in android gradle

我想 运行 一个 shell 脚本来在构建我的应用程序时更改 string.xml 中的值。我应该 运行 我的脚本在 gradle 的什么地方,因为里面没有任务。或者,因为我将使用 Jenkins 构建应用程序,我应该 运行 Jenkins 服务器上的脚本吗?请帮帮我。

    apply plugin: 'com.android.application'

 android {
     compileSdkVersion 22
     buildToolsVersion '22.0.1'
     }

defaultConfig {
   .......
     }

buildTypes {
    release {
      .......
       }
     }

productFlavors {
    development {}
    production {}
     }

sourceSets {
    androidTest {
        setRoot('src/test')
              }
     }

packagingOptions {..}


dependencies {...}

您可以添加一个 preBuild 步骤来运行脚本并使其依赖于构建。

task myPreBuild << {
   commandLine './script.sh'
}
build.dependsOn myPreBuild