intellij与Android SDK:lambda表达式在-source 1.7中不受支持 [英] intellij with Android SDK : lambda expressions are not supported in -source 1.7

查看:786
本文介绍了intellij与Android SDK:lambda表达式在-source 1.7中不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天全部



我知道在这个问题上有各种各样的问题,并且我访问了很多他们,但是他们没有提供任何解决方案 。

一般的答案是将语言级别设置为8(允许使用lambda表达式),就像我为使用grade创建的2个模块所做的那样,见下面









我想确认我已经安装了Java 8

  java -version 
java version1.8.0_141
Java™SE运行时环境(build 1.8.0_141-b15)
Java HotSpot™64位服务器虚拟机(构建25.141-b15,混合模式)

当设置语言级别时,它解决了它在IDE中的问题,但是当构建我的项目以在我的设备上运行时,我得到这个错误:

 信息:Gradle任务[:app:assembleDebug] 
/ home / cybex / Documents / University / Year 5 /第2学期/ WRAP302 - 高级编程2 /作业/作业1 /Task1_SOS2/app/src/main/java/wrap302/nmu/task1_sos/SOSButton.java
错误:(15,25)错误:lambda表达式没有在-source 1.7
支持(使用-source 8或更高版本以启用lambda表达式)
/ home / cybex / Documents / University / Year 5 /第2学期/ WRAP302 - 高级编程2 /作业/作业1 /任务1_SOS2 / app / src / main / java / wrap302 / nmu /task1_sos/MainActivity.java
错误:(85,34)错误:lambda表达式在-source 1.7
中不受支持(使用-source 8或更高来启用lambda表达式)
错误:任务':app:compileDebugJavaWithJavac'的执行失败。
>编译失败;详细信息请参阅编译器错误输出。
信息:BUILD FAILED
信息:总时间:1.054秒
信息:3个错误
信息:0个警告
信息:查看控制台中的完整输出

$ b

更新

项目Gradle构建

 <?xml version =1.0encoding =UTF-8?> 
< component name =FacetManager>
< facet type =java-gradlename =Java-Gradle>
<配置>
< option name =BUILD_FOLDER_PATHvalue =$ MODULE_DIR $ / build/>
< option name =BUILDABLEvalue =false/>
< / configuration>
< / facet>
< / component>
< component name =NewModuleRootManagerLANGUAGE_LEVEL =JDK_1_7inherit-compiler-output =true>
< exclude-output />
< content url =file:// $ MODULE_DIR $>
< excludeFolder url =file://$MODULE_DIR$/.gradle/>
< / content>
< orderEntry type =inheritedJdk/>
< orderEntry type =sourceFolderforTests =false/>
< / component>
< / module>

模块Gradle构建

  apply plugin:'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion26.0.1
defaultConfig {
的applicationID wrap302.nmu.task1_sos
的minSdkVersion 15
targetSdkVersion 26
的versionCode 1个
的versionName 1.0
testInstrumentationRunnerandroid.support.test.runner。 AndroidJUnitRunner
}
buildTypes {
发布{
minifyEnabled假
proguardFiles getDefaultProguardFile( 'proguard的-android.txt'), 'proguard-rules.pro'



$ b依赖关系{
编译fileTree(包括:''.jar'],dir:'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group:'com.android.support',module:'support-annotations '
})
编译'com.android.support:appcompat-v7:26.0.0-alpha1'
compile'c​​om.android.support.constraint:constraint-layout:1.0.2 '
testCompile'junit:junit:4.12'
compile'c​​om.android.support:gridlayout-v7:26.0.0-alpha1'
}


侧面问题:值得关注的问题,每次我改变语言级别为8,然后是gradle change(即添加依赖关系等),语言级别默认为7,这是正常的吗?

解决方案

检查您的构建。 gradle文件。它们可能具有覆盖您在IDE中指定内容的设置。如果是这种情况,请彻底删除设置或修改它们以实现Java 8兼容性。


Good day all

I know there are various questions on this issue, and I have visited quite a number of them, however they do not provide any "solution".

The general answer is to set the Language level to 8 (Allowing for lambdas) as I have done for the 2 modules built with grade, see below

and

I would like to confirm that I have Java 8 install

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 resolves the issue it has in the IDE,but when building my project to run on my devvice, 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 suggesting it may be Gradle issues:

Project Gradle build

<?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>

Module Gradle build

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'
}

To those suggesting that I need to change my project language 8 (from 7), I have done so already (reeason for images as proof), yet my error persists, hence the reason for my question unless I am missing something in plain site.

Side question: something of concern, each time I change an the language level to 8, followed by a gradle change (i.e. added dependency, etc), the language level defaults to 7, is this normal?

解决方案

Check your build.gradle files. They might have settings that override what you specified in the IDE. If this is the case, either remove the settings completely or modify them for Java 8 compatibility.

这篇关于intellij与Android SDK:lambda表达式在-source 1.7中不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆