Java 错误:Android Studio 1.2 RC 3上的-source 1.6不支持开关中的字符串

Java 错误:Android Studio 1.2 RC 3上的-source 1.6不支持开关中的字符串,java,android,android-studio,Java,Android,Android Studio,昨晚我花了几个小时试图让我的项目在Android Studio 1.2 RC 3上使用JDK 1.7进行实际编译 我在这个网站上读了几篇不同的帖子,以及其他一些有类似问题的人的帖子,我尝试了他们提供的解决方案,比如将我的项目的字节码版本设置为1.7,还将我的项目的源兼容性设置为1.7 但我仍然不断得到以下错误: Information:Gradle tasks [:android:assembleDebug] :android:preBuild UP-TO-DATE :android:preDe

昨晚我花了几个小时试图让我的项目在Android Studio 1.2 RC 3上使用JDK 1.7进行实际编译

我在这个网站上读了几篇不同的帖子,以及其他一些有类似问题的人的帖子,我尝试了他们提供的解决方案,比如将我的项目的字节码版本设置为1.7,还将我的项目的源兼容性设置为1.7

但我仍然不断得到以下错误:

Information:Gradle tasks [:android:assembleDebug]
:android:preBuild UP-TO-DATE
:android:preDebugBuild UP-TO-DATE
:android:checkDebugManifest
:android:preReleaseBuild UP-TO-DATE
:core:compileJava
Warning:[options] bootstrap class path not set in conjunction with -source 1.6
 F:\MyProjects\Puzzle Pebbles\core\src\com\mtpmstudios\puzzlepebbles\Pebble.java
 Error:(27, 16) error: strings in switch are not supported in -source 1.6
 (use -source 7 or higher to enable strings in switch)
 Error:(54, 16) error: strings in switch are not supported in -source 1.6
(use -source 7 or higher to enable strings in switch)
1 warning
Error:Execution failed for task ':core:compileJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 6.506 secs
Information:3 errors
Information:1 warning
Information:See complete output in console
我非常感谢大家对我一直以来的问题有任何见解。 多谢各位

更新

这是我的build.gradle文件:

    android {
    buildToolsVersion '21.1.2'
    compileSdkVersion 21

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniFolders = new HashSet<File>()
    pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
        if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if (outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}
task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.mtpmstudios.puzzlepebbles.android/com.mtpmstudios.puzzlepebbles.android.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

    classpath {
        plusConfigurations += [project.configurations.compile]
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}
// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [COMPILE: [plus: [project.configurations.compile]]]

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value: "true")
                        }
                    }
                }
            }
        }
    }
}
dependencies {
}

repositories {
    mavenCentral()
    mavenLocal()
}
android{
buildToolsVersion'21.1.2'
编译DK21版
源集{
主要{
manifest.src文件“AndroidManifest.xml”
java.srcDirs=['src']
aidl.srcDirs=['src']
renderscript.srcDirs=['src']
res.srcDirs=['res']
assets.srcDirs=['assets']
}
instrumentTest.setRoot('tests'))
}
编译选项{
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
//在CLI上编译时需要将JNI共享库添加到APK
tasks.withType(com.android.build.gradle.tasks.PackageApplication){pkgTask->
pkgTask.jniFolders=new HashSet()
pkgTask.jniFolders.add(新文件(projectDir,'libs'))
}
//每次执行gradle时调用,获取
//本地配置,并将它们提取到适当的libs/文件夹中
//所以他们被APK包围了。
任务copyAndroidNatives(){
文件(“libs/armeabi/”).mkdirs();
文件(“libs/armeabi-v7a/”).mkdirs();
文件(“libs/x86/”).mkdirs();
configurations.natives.files.each{jar->
def outputDir=null
if(jar.name.endsWith(“natives-armeabi-v7a.jar”))outputDir=file(“libs/armeabi-v7a”)
if(jar.name.endsWith(“natives armeabi.jar”))outputDir=file(“libs/armeabi”)
if(jar.name.endsWith(“natives-x86.jar”))outputDir=file(“libs/x86”)
if(outputDir!=null){
抄袭{
来自zipTree(罐子)
输入输出目录
包括“*.so”
}
}
}
}
任务运行(类型:Exec){
def路径
def localProperties=project.file(“../local.properties”)
if(localProperties.exists()){
属性=新属性()
localProperties.withInputStream{instr->
属性。加载(instr)
}
def sdkDir=properties.getProperty('sdk.dir')
中频(sdkDir){
path=sdkDir
}否则{
path=“$System.env.ANDROID\u HOME”
}
}否则{
path=“$System.env.ANDROID\u HOME”
}
def adb=路径+“/平台工具/adb”
命令行“$adb”,“shell”,“am”,“start”,“n”,“com.mtpmstudios.puzzpebbles.android/com.mtpmstudios.puzzpebbles.android.AndroidLauncher”
}
//使用旧的基于Ant的构建设置Android Eclipse项目。
蚀{
//需要明确指定Java源代码集,SpringSource Gradle Eclipse插件
//忽略在classpath.file.withXml中添加的任何节点
源集{
主要{
java.srcDirs“src”,“gen”
}
}
jdt{
sourceCompatibility=1.7
targetCompatibility=1.7
}
类路径{
plusConfiguration+=[project.configurations.compile]
容器“com.android.ide.eclipse.adt.android_FRAMEWORK”、“com.android.ide.eclipse.adt.LIBRARIES”
}
计划{
name=appName+“-android”
natures'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand“com.android.ide.eclipse.adt.ResourceManagerBuilder”
buildCommand“com.android.ide.eclipse.adt.PreCompilerBuilder”
buildCommand“org.eclipse.jdt.core.javabuilder”
buildCommand“com.android.ide.eclipse.adt.ApkBuilder”
}
}
//使用旧的基于Ant的构建建立Android Idea项目。
意念{
模块{
sourceDirs+=文件(“src”);
范围=[COMPILE:[plus:[project.configurations.COMPILE]]
iml{
withXml{
def node=it.asNode()
def builder=NodeBuilder.newInstance();
builder.current=节点;
构件(名称:“FacetManager”){
刻面(类型:“安卓”,名称:“安卓”){
配置{
选项(名称:“更新属性文件”,值:“真”)
}
}
}
}
}
}
}
依赖关系{
}
存储库{
mavenCentral()
mavenLocal()
}

我假设您最初一定是在IDE上创建了符合JDK1.6的项目。 我在这里发现的问题在您的构建脚本中。 如果您安装了多个JDK,并且如果您动态地尝试更改项目的Java版本,编译器将优先考虑创建当前项目的Java版本

在访问同时安装了JDK7和JDK8的JavaFX8组件时,我遇到了同样的问题。(我以前的项目是以1.7作为目标平台创建的)


您可以通过在IDE中创建一个目标JDK版本为1.7或更高版本的新项目,然后将以前项目中的所有源文件复制到新创建的项目路径来修复此问题。在本例中,IDE创建的构建脚本现在将指向JDK 7

请发布build.gradle文件。我最好的猜测是看看这个:我更新了我的原始帖子,加入build.gradle文件。谢谢你,但我已经看过那篇文章了,之后它仍然没有编译。你能通过命令行构建它吗
gradlew AssembledBug
?我试过了