Android使用场景

Android Studio 3.0 支持直接添加Java1.8

2018-12-06  本文已影响203人  雩航

Android Studio 3.0 以上直接添加Java1.8,就可以使用java1.8特性,比如对lambda表达式的支持,父类推断等。

在app build.gradle 添加

android{
    defaultConfig{
        //默认
    }
    compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
    }
}

之前老版本迁移到Android Studio会报:

WARNING: One of the plugins you are using supports Java 8       language features. To try the support built into the Android plugin, remove the   following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'
To learn more, go to https://d.android.com/r/tools/java-8-support-        message.html
Affected Modules: app

ERROR: Could not find method retrolambdaConfig() for arguments [net.orfjackal.retrolambda:retrolambda:2.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

这些问题需要在app 以及 project 的build.gradle 删除
1.app build.gradle:

 apply plugin: 'me.tatarka.retrolambda'
 retrolambdaConfig "net.orfjackal.retrolambda:retrolambda:${"2.3.0"}"

2.project build.gradle:

  classpath 'me.tatarka:gradle-retrolambda:3.2.4'
上一篇下一篇

猜你喜欢

热点阅读