错误: -source 1.7 中不支持 lambda 表达式 (请使用 -source 8 或更高版本以启用 lambda 表达式)

在IDEA中编写Android APP时,使用了JDK8才出现的Lambda表达式,结果编译时出现 错误: -source 1.7 中不支持 lambda 表达式 (请使用 -source 8 或更高版本以启用 lambda 表达式)

解决方法:

     1、将项目和module的JDK全改成1.8的

     2、修改build.gradle文件,添加如下黄色代码内容

 1 apply plugin: 'com.android.application'
 2 
 3 android {
 4     compileSdkVersion 28
 5 
 6     compileOptions {
 7         sourceCompatibility JavaVersion.VERSION_1_8
 8         targetCompatibility JavaVersion.VERSION_1_8
 9     }
10 
11     defaultConfig {
12         applicationId "com.trojane.android.learnactivity"
13         minSdkVersion 24
14         targetSdkVersion 28
15         versionCode 1
16         versionName "1.0"
17         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18     }
19     
20     buildTypes {
21         release {
22             minifyEnabled false
23             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24         }
25     }
26 }
27 

       3、刷新Gradle,编译成功。 

posted @ 2018-11-27 10:27  一只假喵  阅读(5871)  评论(0)    收藏  举报