每当导入现有的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:别忘了,您还必须更改支持库的主要版本.
原文地址:https://codeday.me/bug/20191110/2015281.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。