programing

안드로이드:Dex는 버전 52 바이트 코드를 구문 분석할 수 없습니다.

bestcode 2022. 11. 8. 21:50
반응형

안드로이드:Dex는 버전 52 바이트 코드를 구문 분석할 수 없습니다.

방금 Android Studio 2.1로 전환했는데 이전에 동작하던 앱을 컴파일하려고 할 때 다음과 같은 오류가 발생했습니다.

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

저는 이미 메인 프로젝트의 그라들을 업데이트했습니다.Java 1.7 코드 생성을 강제하는 빌드 파일:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        apply plugin: 'java'
        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }
}

모듈 gradle도 업데이트했습니다.다음과 같이 빌드하여 Java 버전을 설정합니다.

android {
compileSdkVersion 19
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.abc.def"
    minSdkVersion 19
    targetSdkVersion 19
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
}

이븐메.7 generation.pom.xml을 하려고 했습니다.
하위 모듈을 포함하는 어셈블리 아티팩트를 사용하고 있는 것은 알고 있습니다만, 하위 모듈을 변경하지 않았기 때문에 마지막으로 컴파일 했을 때 모듈의 .jar 파일이 정상적으로 실행되었습니다.

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId> <!-- maven-compiler-plugin -->
            <version>2.6</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target> 
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

질문: 1) 이것이 Android Studio 2.1의 문제입니까?다른 사람이 본 적이 있습니까?2) 이것이 제 오류라고 가정하고 오류 메시지가 불량 모듈을 찾는 데 도움이 되지 않으므로 V52 코드를 찾는 데 권장되는 방법이 있습니까?많은 양의 암호를 해독하지 않고는 도서관을 그냥 생략할 수 없다.코드 리비전을 찾기 위해 .jar 파일을 검사할 수 있습니까?잘 부탁드립니다.-헤파이스토스

Android Studio 3.0+에서 java 1.8을 사용하고 다음 기능을 설정하기만 하면 됩니다.최신 빌드 툴이 필요한 것 같습니다.

classpath 'com.android.tools.build:gradle:3.0.0'

그리고.

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        ...        
        //jackOptions { // DEPRECATED
            //enabled true
        //}
    }
    dexOptions {
        incremental true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Android 고유하지 않은 Java 라이브러리를 가진 모듈이 있는 경우 다음과 같이 작동합니다.apply plugin:'java'

build.gradle 파일의 맨 위에 배치한 후 다시 빌드합니다.

    apply plugin: 'java'
    apply plugin: 'jacoco'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.11'

        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

「 」를 사용하고 org.jetbrains:annotation:15하여 line retrolambda를 합니다.compile org.jetbrains:annotations:15.0의 서 build.gradle그러면 오류가 사라집니다.저는 좋아요.

아마도 당신의 의존관계 중 일부는 특별히 Android가 아닌 Java 8로 컴파일되었을 것입니다.종속성을 이전 버전으로 전환해 보십시오.메인 모듈의 종속성 목록을 첨부하지 않았기 때문에 어떤 라이브러리를 다운그레이드해야 하는지 정확히 모르겠습니다.

예를 들어 다음과 같습니다.★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ 찾아본 그 도서관을 했습니다.org.codehaus.httpcache4j.uribuilder:2.0.0github에서는 Java 8이 필요합니다.그래서, 내가 다른 곳으로 옮겼을 때1.1.0

섹션의 모든 프로젝트에서 main build.gradle에 추가해 보겠습니다.

tasks.withType(JavaCompile) {
    sourceCompatibility = "1.7"
    targetCompatibility = "1.7"
}

또는 이것을 의존관계에 추가합니다.

    sourceCompatibility = 1.7
    targetCompatibility = 1.7

모든 모듈에서 수동으로

다음 행을 추가하여 이 문제를 해결할 수 있었습니다.

jackOptions {
    enabled true
}

로.defaultConfigbuild.gradle파일.

Java 8의 가이드라인은 링크에서 확인할 수 있습니다.https://developer.android.com/guide/platform/j8-jack.html

저도 GREENDAO 발전기 의존성에 대해 같은 문제가 있었습니다.실수로 그 의존성을 build.gradle에 추가했습니다.compile 'org.greenrobot:greendao-generator:3.1.0'Android Studio에서도 같은 에러 메세지가 표시되었습니다.

아마도 그 모듈은 Java 8로 컴파일 되어 있기 때문일 것입니다.

그래서 저는 그 의존관계를 build.gradle에서 삭제하고 모두 행복하게 컴파일했습니다.

저는 이 문제를 다음과 같이 해결했습니다.

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Gradle 플러그인 2.2.2를 탑재한 Android Studio 2.2의 Instant Run을 끄면 수정이 되었습니다.이전 버전의 Gradle 플러그인(예: 2.2.0)으로 다시 전환해도 수정되지만, 이는 바람직하지 않습니다.

Android Studio 2.3.3에서 일어난 일입니다.제가 찾은 해결책은 빌드 폴더를 삭제하고 프로젝트를 재구축하는 것이었습니다.그것은 그렇게 간단했다.

나 또한 같은 오류에 직면했다.Android 2.3.3JAR 디펜시스를 몇 개 추가한 후.문제는 퇴폐였다.io.netty:netty-all:4.1.16.Final이 4.1.16 버전 JAR은 Java 1.8로 컴파일되었으며 기타 모든 버전은 Java 1.7로 생성되었습니다.

이 문제는 이전 버전을 포함하면 해결됩니다.netty(Java 1.7에서 생성됨)을 사용하여build.gradle파일.

compile 'io.netty:netty-all:4.1.5.Final'

Android Studio v2.3.3에서 auto-value v1.5로 업그레이드 할 때 이 문제가 발생하였습니다.auto-value 1.5는 AS 3과 호환성이 있을 것으로 생각됩니다(업데이트된 Java 컴파일러 필요).

현재 자동값 1.4.1이 작동합니다.

Android RxJava 2용 Reactive Location APIs Library에서도 같은 문제에 직면해 있습니다.build.gradle을 3.0.1로 업데이트하고 Reactive Location APIs Library for Android 및 RxJava 2 라이브러리 버전을 1.0.4에서 1.0.3으로 줄이면 됩니다.내 경우는 정상적으로 동작합니다.

Android Studio 3.0에서 jdk 1.8로 컴파일된 jar를 Import 할 때 이 문제가 발생하였습니다.위의 모든 솔루션을 시도해 봤지만 효과가 없었습니다.그래서 그 jar 개발자에게 jdk 1.7로 다시 컴파일을 해보라고 부탁했더니 잘 작동하지만 이 문제는 다시 발생하지 않습니다.

가능한 경우:

  1. Android 도구를 classpath 'com.android로 업그레이드합니다.tools.build: 그라들: 3.0.0'
  2. buildToolsVersion "26.0.2"

이것으로 문제가 해결됩니다.

참고 자료: https://developer.android.com/studio/write/java8-support

언급URL : https://stackoverflow.com/questions/37020413/android-dex-cannot-parse-version-52-byte-code

반응형