Execute shell script in android gradle

2019-09-08 23:15发布

I want to run a shell script to change the value in string.xml when my app is built. Where should I run my script in gradle, since there is no task in it. Or, because I will build the app use Jenkins, should I run the script on Jenkins server? Please help me out.

    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 {...}

1条回答
孤傲高冷的网名
2楼-- · 2019-09-08 23:39

You can add a preBuild step that runs the script and makes it depend on build.

task myPreBuild << {
   commandLine './script.sh'
}
build.dependsOn myPreBuild
查看更多
登录 后发表回答