在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,編譯成功。