Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code

Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code

我有一个非常奇怪的错误。我使用 android studio 2.3.

首先请看我的gradle档案。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "com.example.name.webrtcwork"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    sourceSets.main {
        jniLibs.srcDir 'libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.myhexaville:smart-image-picker:1.0.4'
    compile 'pub.devrel:easypermissions:1.1.3'
    compile('io.socket:socket.io-client:1.0.0') {
        exclude group: 'org.json', module: 'json'
    }
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    compile files('libs/autobanh.jar')
    compile files('libs/base_java.jar')
    compile files('libs/libjingle_peerconnection.jar')

    testCompile 'junit:junit:4.12'
}

项目清理和重建工作成功,但如果我想 运行 应用程序,我会收到这样的错误。

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.

Error:1 error; aborting

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/Hayk.Mkrtchyan/.android/build-cache/7fd66238e8a360302161a82746a2b9f0a8b83132/output/jars/classes.jar' to '/Users/Hayk.Mkrtchyan/Desktop/WebRTCWork/app/build/intermediates/pre-dexed/debug/classes_547e5465c50bca12a58d5755bafa9d6a10538b52.jar'

好的,我尝试了很多方法来解决问题,比如在我的构建文件中添加 targetCompatibility = '1.7' sourceCompatibility = '1.7'。这行不通。

我不想添加 1.8 版,也不想将我的 android 工作室版本升级到 3.0。我该如何解决这个问题?

如果我添加 1.8 版本并启用插孔,它也会报错。

Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'. Cannot load Jill from build tools.

我该如何解决这个问题?

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.

仅供参考

  • 所有com.android.support:版本应该相同。

Android Studio 3.0 及更高版本支持所有 Java 7 种语言功能和 Java 8 种语言功能的子集,具体因平台版本而异。 也可以直接在对应的build.gradle文件中配置:

android {
  ...
  // Configure only for each module that uses Java 8
  // language features (either in its source code or
  // through dependencies).
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

阅读Use Java 8 language features

谢谢大家的回答。问题是这个库 (compile 'com.myhexaville:smart-image-picker:1.0.4') 产生了冲突。当我删除它时,一切终于正常了。