Intellij with Android SDK: lambda expressions are not supported in -source 1.7
Good afternoon everyone
I know there are various questions about this problem and I have visited quite a few of them, however they do not provide any "solution".
The general answer is to set the language level to 8 (valid for lambdas), as was done for 2 units built with a degree, see below
and
I want to confirm that I have Java 8 installed
java -version
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
When setting the language level, it fixes the problem the IDE had, but when building my project on my device, I get this as an error:
Information:Gradle tasks [:app:assembleDebug]
/home/cybex/Documents/University/Year 5/Semester 2/WRAP302 - Advanced Programming 2/Assignments/Assignment1/Task1_SOS2/app/src/main/java/wrap302/nmu/task1_sos/SOSButton.java
Error:(15, 25) error: lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)
/home/cybex/Documents/University/Year 5/Semester 2/WRAP302 - Advanced Programming 2/Assignments/Assignment1/Task1_SOS2/app/src/main/java/wrap302/nmu/task1_sos/MainActivity.java
Error:(85, 34) error: lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 1.054 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
Any thoughts?
UPDATE
For those who suggested it might be a Gradle issue:
Gradle build project
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Task1_SOS2" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Gradle build module
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "wrap302.nmu.task1_sos"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:gridlayout-v7:26.0.0-alpha1'
}
For those suggesting that I change my project language 8 (from 7), I already did this (reeason for images as proof), but my error persists, hence the reason for my question if I don't see something in a simple site.
Side question: Something is troubling, every time I change the language level to 8 followed by a Gradle change (i.e. added dependency, etc.), the default language level is 7, is this normal?
source to share
I am using Android Studio 3.0 Beta 4. With this version adding the following lines for build.gradle (Module: app) does the trick. See also: https://developer.android.com/studio/write/java8-support.html
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
source to share