升級Android Studio3.0遇到問題總結(jié)

更新到3.0官方頁面:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

1.Java 8 language

在以前官網(wǎng)給出的方法,你可以使用me.tatarka.retrolambda這個插件,但是3.0中,這個方法不讓使用了,官網(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)然,如果不用的話官網(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"
        ...
    }
}

通過上面的例子可以發(fā)現(xiàn),現(xiàn)在在外層需要多定義一個flavorDimensions,然后每個Flavors里面要加dimension,很好理解吧。官網(wǎng)地址:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?utm_source=android-studio#apply_plugin

3.項目根目錄下build.gradle的變化

google support都已經(jīng)升級到26.1.0了,但是為什么你的down不下來呢,因為google這些東西放到新的倉庫里面了,按照下面修改,出處地址:https://developer.android.com/topic/libraries/architecture/adding-components.html

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

4.第三方庫以來方式

從compile改為implementation

從provided改為compileOnly

從apk改為runtimeOnly

從compile改為api

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容