gradle 的版本需要升級(jí)4.1+,建議直接用4.3版本
gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
添加 google倉(cāng)庫(kù)
gradle plugin 3.0.0+、support library 27+開始只放在了google倉(cāng)庫(kù)中了,不再jcenter中提供了
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
buildToolsVersion
Android Studio 3.0.0 默認(rèn)可以不寫buildToolsVersion,默認(rèn)最低可用版本26.0.2
手動(dòng)修改 buildToolsVersion>=26.0.2
設(shè)置了productFlavors的必須設(shè)置flavorDimensions
buildType match問題
gradle 依賴的API變更
為了兼容使用gradle 4.3,目前是標(biāo)記為廢棄的,4.3后直接沒了
compile -> implementation (for app module)
compile -> api ( for sub module)
provided -> compileOnly
apk-> runtimeOnly
Studio 3.0 minimum
Error:This Gradle plugin requires Studio 3.0 minimum
gradle.properties
android.injected.build.model.only.versioned=3
aapt2問題
AS3默認(rèn)使用aapt2處理,如果一些項(xiàng)目使用aapt2有問題,那么可以禁用掉,繼續(xù)使用原有的aapt。
gradle.properties
android.enableAapt2=false
獲取manifest文件路徑
修改apk名問題
以前的方式是 output.outputFile = xxxx
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=normalDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
正確的姿勢(shì)
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
具體參考:
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html