美文网首页Android使用场景
Android Studio 3.0 支持直接添加Java1.8

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

作者: 雩航 | 来源:发表于2018-12-06 14:13 被阅读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'
    

    相关文章

      网友评论

        本文标题:Android Studio 3.0 支持直接添加Java1.8

        本文链接:https://www.haomeiwen.com/subject/saqocqtx.html