在Android Gradle中执行Shell脚本 [英] Execute shell script in android gradle

查看:1061
本文介绍了在Android Gradle中执行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

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

这篇关于在Android Gradle中执行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆