关于settings.gradle的变化
之前的版本仅仅包含了项目和module的配置
rootProject.name = "My Application"
include ':app'
include ':mylibrary'
新版本中也增加了插件的配置
pluginManagement {
repositories {
//注意由于项目中配置了私服maven,且使用http地址,需要在maven中配置allowInsecureProtocol = true
maven {
url "http://xxxxxxxx/repository/maven-public/"
allowInsecureProtocol = true
}
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//注意由于项目中配置了私服maven,且使用http地址,需要在maven中配置allowInsecureProtocol = true
maven {
url "http://xxxxxxxx/repository/maven-public/"
allowInsecureProtocol = true
}
maven { url "https://jitpack.io" }
google()
mavenCentral()
}
}
rootProject.name = "My Application"
include ':app'
include ':mylibrary'
关于项目的build.gradle的变化
buildscript {
ext {
kotlin_version = '1.6.10'
}
dependencies {
classpath "com.alibaba:arouter-register:1.0.2"
}
}
plugins {
id 'com.android.application' version '7.3.0-alpha04' apply false
id 'com.android.library' version '7.3.0-alpha04' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
apply from: "config.gradle"
app或者module内的build.gradle的变化
其中部分关键词进行了缩短优化
apply plugin变更为plugins
apply from还可以正常使用
部分属性更名
属性 |
Old |
New |
参与编译 SDK 版本 |
compileSdkVersion |
compileSdk |
最小支持 SDK 版本 |
minSdkVersion |
minSdk |
目标 SDK 版本 |
targetSdkVersion |
targetSdk |
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
apply from 'xxx.gradle'
android {
//指定包名
namespace "com.xxx.xxx"
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 31
//对于 com.android.library 类型的 Module 默认不再需要 versionCode 和 versionName 属性.
versionCode 1
versionName rootProject.ext.MAPCOM_VERSION
/**
* BuildConfig文件中有属性找不到,形成原因:老版本的gradle会把defaultConfig中的versionCode和
* versionName属性自动变成VERSION_CODE和VERSION_NAME属性加在BuildConfig文件中,
* 而新版本的gradle文件不会管这个
*/
buildConfigField "String", "VERSION_NAME", "\"${rootProject.ext.MAPCOM_VERSION}\""
}
...
}
重大更改:
1、构建选项默认值
Flag |
新的默认值 |
以前的默认值 |
说明 |
android.defaults.buildfeatures.buildconfig |
false |
true |
AGP 8.0 默认不产生BuildConfig |
android.defaults.buildfeatures.aidl |
false |
true |
AGP 8.0 默认不启用AIDL支持 |
android.defaults.buildfeatures.renderscript |
false |
true |
AGP 8.0 默认不启用RenderScript支持 |
android.nonFinalResIds |
true |
false |
AGP 8.0 默认使用non-final fields产生R类 |
android.nonTransitiveRClass |
true |
false |
AGP 8.0仅为当前模块中定义的资源生成R类。 |
android.enableR8.fullMode |
true |
false |
AGP 8.0 默认启用 R8 完整模式。更多详情请参见 R8全模式。 |
2、具体设置方式为:
在模块中设置,只对该模块生效:
android {
buildFeatures {
buildConfig = true
}
}
在gradle.properties中添加一行,对所有模块生效:
android.defaults.buildfeatures.buildconfig = true