android grade 命令,android-Gradle命令行参数来覆盖build.gradle中的属性

每当导入现有的android项目时,在大多数情况下,我们都需要在安装的工具版本号之后更改值

在project / build.gradle中

buildscript {

...

dependencies {

classpath 'com.android.tools.build:gradle:x.x.x'

}

}

在project / app / build.gradle中

android {

compileSdkVersion xx

buildToolsVersion "xx.x.x"

defaultConfig {

applicationId "com.example.app.xyz"

minSdkVersion xx

targetSdkVersion xx

versionCode x

versionName "x.x"

}

...

}

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])

testCompile 'junit:junit:x.xx'

compile 'com.android.support:appcompat-v7:xx.x.x'

compile 'com.android.support:recyclerview-v7:xx.x.x'

}

如何覆盖以上的值

classpath

compileSdkVersion

buildToolsVersion

targetSdkVersion

使用命令行参数例如

./gradlew installDebug -PCompileSdkVersion=26 -PbuildToolsVersion=26.0.0

或类似的东西?

我的想法是使用一个相同的命令(以我已安装的sdk版本号作为参数)来构建我不维护的任何项目.

如果我们必须构建由他人管理的多个项目,这将很有帮助.它可以通过命令行参数覆盖我们的构建配置,从而节省大量时间,因此我们不需要每次都通过在每个特定位置进行更改来更改它新导入的项目.

解决方法:

输入您的gradle.properties默认值:

SDK_VERSION=26

在build.gradle中使用:

android {

compileSdkVersion project.getProperties().get("SDK_VERSION")

}

使用:./ gradlew build -PSDK_VERSION = 26

PS:别忘了,您还必须更改支持库的主要版本.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值