【Android】 Android使用Java 8 语言功能注意

2019-02-25  本文已影响0人  李翾

Android studio 3.0以前,如果我们要使用Java 8的语言功能如Lamb表达式,我们需要这么配置:
工程的build.gradle里面配置如下:

buildscript {
  ...
   dependencies {
      // Remove the following dependency.
      classpath 'me.tatarka:gradle-retrolambda:<version_number>'
   }
}

app或者每个模块中的 build.gradle配置如下:

// 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](https://docs.gradle.org/current/userguide/build_environment.html) file.
    jvmArgs '-Xmx2048m'
}</pre>

可能还会配置如下的:

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
    }
}

Android studio升级到3.0以后以上统统不需要了,只需要在app或者每个module里面做如下配置:

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

参考链接:
1.https://developer.android.com/studio/write/java8-support?utm_source=android-studio

上一篇 下一篇

猜你喜欢

热点阅读