更新到3.0官方頁(yè)面:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
1.Java 8 language
在以前官網(wǎng)給出的方法涛漂,你可以使用me.tatarka.retrolambda這個(gè)插件娜睛,但是3.0中,這個(gè)方法不讓使用了,官網(wǎng)地址(需要梯子):https://developer.android.com/studio/write/java8-support.html?utm_source=android-studio
To disable Jack and switch to the default toolchain, simply remove the jackOptions block from your module’s build.gradle file:
android {
...
defaultConfig {
...
// Remove this block.
jackOptions {
enabled true
...
}
}
// Keep the following configuration in order to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Compared to Android Studio's default toolchain, Retrolambda lacks support for third party libraries that use Java 8 language features. To migrate to the default toolchain, remove the Retrolambda dependency from your project-level build.gradle file:
buildscript {
...
dependencies {
// Remove the following dependency.
classpath 'me.tatarka:gradle-retrolambda:<version_number>'
}
}
And remove the Retrolambda plugin and retrolambda block from each module's build.gradle file:
// Remove the following plugin.
apply plugin: 'me.tatarka.retrolambda'
...
// Remove this block after migrating useful configurations.
retrolambda {
...
// If you have arguments for the Java VM you want to keep,
// move them to your project's gradle.properties file.
jvmArgs '-Xmx2048m'
}
當(dāng)然凌蔬,如果不用的話(huà)官網(wǎng)也給了方法:修改gradle.properties
android.enableDesugar=false
2.productFlavors改變
// Specifies two flavor dimensions.
flavorDimensions "tier", "minApi"
productFlavors {
free {
// Assigns this product flavor to the "tier" flavor dimension. Specifying
// this property is optional if you are using only one dimension.
dimension "tier"
...
}
paid {
dimension "tier"
...
}
minApi23 {
dimension "minApi"
...
}
minApi18 {
dimension "minApi"
...
}
}
通過(guò)上面的例子可以發(fā)現(xiàn)茫多,現(xiàn)在在外層需要多定義一個(gè)flavorDimensions,然后每個(gè)Flavors里面要加dimension,很好理解吧锌蓄。官網(wǎng)地址:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?utm_source=android-studio#apply_plugin
3.項(xiàng)目根目錄下build.gradle的變化
google support都已經(jīng)升級(jí)到26.1.0了稠项,但是為什么你的down不下來(lái)呢涯雅,因?yàn)間oogle這些東西放到新的倉(cāng)庫(kù)里面了,按照下面修改慎菲,出處地址:https://developer.android.com/topic/libraries/architecture/adding-components.html
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
4.第三方庫(kù)以來(lái)方式
從compile改為implementation
從provided改為compileOnly
從apk改為runtimeOnly
從compile改為api