0

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

1 Answer 1

3

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

task myPreBuild << {
   commandLine './script.sh'
}
build.dependsOn myPreBuild
Sign up to request clarification or add additional context in comments.

4 Comments

thanks. BTY, where should I put my script? In res/raw/ or somewhere else?
Im not too sure. I usually put mine in a scripts folder.
I use preBuild.dependsOn command, it can recognize. But the build failed, maybe some problem with my path? I put the script on my local "commandLine 'sh /home/czhu/lokki/editxml.sh' ".
Your probably need to prepend with 'sh', e.g. 'sh ./script.sh'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.