Android studio

升级Android Studio3.0遇到问题总结

2017-10-26  本文已影响237人  lhl_012

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

1.Java 8 language

在以前官网给出的方法,你可以使用me.tatarka.retrolambda这个插件,但是3.0中,这个方法不让使用了,官网地址(需要梯子):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'
}

当然,如果不用的话官网也给了方法:修改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"
        ...
    }
}

通过上面的例子可以发现,现在在外层需要多定义一个flavorDimensions,然后每个Flavors里面要加dimension,很好理解吧。官网地址:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?utm_source=android-studio#apply_plugin

3.项目根目录下build.gradle的变化

google support都已经升级到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

上一篇下一篇

猜你喜欢

热点阅读