Programming

Android Studio 및 Gradle에서 -source 1.7을 설정하는 방법

procodes 2020. 5. 20. 22:03
반응형

Android Studio 및 Gradle에서 -source 1.7을 설정하는 방법


Android Studio에서 프로젝트를 컴파일하려고 할 때 다음 오류가 발생합니다.

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

내가 찾은 모든 프로젝트 환경 설정에서 1.7을 대상으로 설정했습니다. 또한 1.7 SDK 아래의 프로젝트 SDK에 표시된 경로는 Java 1.7 설치의 올바른 경로입니다.

터미널에서 java -version을 실행하더라도 Java 1.7에서 실행 중임을 알려줍니다.

JAVA_HOME env 변수를 다음과 같이 설정하려고했습니다.

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

오류는 사라지지 않습니다. 오류를 어떻게 제거합니까?


Java 7 지원은 빌드 도구 19에서 추가되었습니다. 이제 다이아몬드 연산자, 멀티 캐치, 리소스 사용, 스위치의 문자열 등과 같은 기능을 사용할 수 있습니다 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
    }
}

Gradle 1.7 이상, Android gradle 플러그인 0.6. 이상이 필요합니다.

참고로 minSdkVersion19 개의 리소스 만 사용해야 합니다. 다른 기능은 이전 플랫폼에서 작동합니다.

Android Gradle 플러그인 사용 설명서에 연결

소스와 타겟이 어떻게 다른지 보려면 링크


위의 답변이 오래되었지만 새로운 Android Studios 1에서는 다음과 같이 1.7 (또는 원하는 경우 1.6)에서 모듈이 실행되는 것을 볼 수 있습니다. 파일-> 프로젝트 구조를 클릭하십시오. 실행할 모듈을 선택한 다음 "Source Compatibility"및 "Target Compatibility"에서 1.7을 선택하십시오. "확인"을 클릭하십시오.

안드로이드 스튜디오의 프로젝트 구조 화면 1


새로운 Android 스튜디오 버전 (0.8.X)에서 변경할 수 있습니다

파일-> 기타 설정-> 기본 설정-> 컴파일러 (왼쪽 화살표를 클릭하여 확장)-> Java 컴파일러-> 여기에서 프로젝트 바이트 코드 버전을 변경할 수 있습니다

여기에 이미지 설명을 입력하십시오


최신 Android Studio 1.4.

파일-> 프로젝트 구조-> SDK 위치-> JDK 위치를 누르십시오.

You could also set individual module JDK Version compatibility by going to the Module (below the SDK Location), and edit the Source Compatibility accordingly. (note, this only applies to Android Module).


Right click on your project > Open Module Setting > Select "Project" in "Project Setting" section

Change the Project SDK to latest(may be API 21) and Project language level to 7+


At current, Android doesn't support Java 7, only Java 6. New features in Java 7 such as the diamond syntax are therefore not currently supported. Finding sources to support this isn't easy, but I could find that the Dalvic engine is built upon a subset of Apache Harmony which only ever supported Java up to version 6. And if you check the system requirements for developing Android apps it also states that at least JDK 6 is needed (though this of course isn't real proof, just an indication). And this says pretty much the same as I have. If I find anything more substancial, I'll add it.

Edit: It seems Java 7 support has been added since I originally wrote this answer; check the answer by Sergii Pechenizkyi.


항상 최신 SDK 버전을 사용하여 빌드하십시오.

compileSdkVersion 23

그것은 않습니다 런타임 동작에 영향을 미치지 만, 당신에게 최신 프로그래밍 기능을 제공합니다.


Gradle로 이동하여 sourceCompatibility를 찾아 1.6 에서 7로 변경하십시오 . 그것은 적어도 나를 위해 일했습니다.

모듈 설정으로 이동하여 소스 / 대상 호환성 을 1.7로 설정할 수도 있습니다 .

모듈 설정 창

Gradle에 다음 코드가 생성됩니다.

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

참고 URL : https://stackoverflow.com/questions/17637179/how-to-set-source-1-7-in-android-studio-and-gradle

반응형