如何设置-source 1.7的Andr​​oid Studio和摇篮 [英] How to set -source 1.7 in Android Studio and Gradle

查看:184
本文介绍了如何设置-source 1.7的Andr​​oid Studio和摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译我的Andr​​oid Studio中项目时收到以下错误:

I'm getting following error when trying to compile my project in Android Studio:

Gradle: error: diamond operator is not supported in -source 1.6

我有1.7设为目标中的所有项目preferences我发现。此外,根据1.7 SDK显示在项目SDK的路径是对Java 1.7的安装正确的路径。

I have 1.7 set as target in all project preferences I've found. Also the path displayed in project SDK's under 1.7 SDK is correct path to java 1.7 installation.

甚至当我运行在终端Java的版本,它告诉我,我java的运行1.7

Even when I run java -version in terminal, it tells me I'm running on java 1.7.

我试图JAVA_HOME环境变量设置为这样的:

I have tried to set JAVA_HOME env variable to this:

/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home

错误不会消失。我如何消除错误?

The error does not go away. How do I eliminate the error?

推荐答案

Java 7的支持,在构建工具添加19现在可以使用的功能,如钻石运营商,多抓,尽量-与资源,在开关串等添加以下到你的的build.gradle

Java 7 support was added at build tools 19. You can now use features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the following to your build.gradle.

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

摇篮1.7+的Andr​​oid插件的gradle 0.6 +是必需的。

Gradle 1.7+, Android gradle plugin 0.6.+ are required.

请注意,只有具有资源尽量要求的minSdkVersion 19.其他功能适用于previous平台。

Note, that only try with resources require minSdkVersion 19. Other features works on previous platforms.

<一个href=\"http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7\">Link到Android插件的gradle用户指南

<一个href=\"http://stackoverflow.com/questions/16654951/gradle-sourcecompatibility-vs-targetcompatibility\">Link看到源代码对目标如何不同

这篇关于如何设置-source 1.7的Andr​​oid Studio和摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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