Android 将字节码转换为 dex : Cause: Dex cannot parse version 52 byte code 时出错

标签 android android-ndk android-gradle-plugin samsung-knox

我使用 samsung knox sdk 并更新 knox 版本 (2.7.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. ...while parsing android/app/enterprise/knoxcustom/CustomDeviceManager.class

我的毕业典礼

  apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            minSdkVersion.apiLevel 14
            targetSdkVersion.apiLevel 25
            versionCode 14
            versionName "2.0.14"
            multiDexEnabled true
        }

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

        ndk {
            moduleName "samsung_custom"
           .....
        }

        buildTypes {
            release {
                minifyEnabled false
                signingConfig = $("android.signingConfigs.sign")
                proguardFiles.add(file('proguard-android.txt'))
                proguardFiles.add(file('proguard-rules.txt'))
            }

            debug {
                signingConfig = $("android.signingConfigs.sign")
            }
        }

        productFlavors {
            create("pro") {
                applicationId = "com.xxxxxx"
                signingConfig = $("android.signingConfigs.sign")
                ndk.abiFilters.add("armeabi-v7a")
            }
            create("basic") {
                applicationId = "com.xxxxx"
                signingConfig = $("android.signingConfigs.sign")
                ndk.abiFilters.add("armeabi-v7a")
            }
        }
    }

    /*
    adroid.sourceSets {
        main {
            aidl.srcDirs = ['src/main/java']
        }
    }
    */

    android.lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    android.packagingOptions {
        pickFirst 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }

    android.dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'joda-time:joda-time:2.9.4'
    compile 'com.google.android.gms:play-services:10.2.0'
    compile 'com.google.android.gms:play-services-gcm:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-plus:10.2.0'
    compile(
            [group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.7.3'],
            [group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.7.3'],
            [group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.3']
    )
    compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    // compile'com.squareup.retrofit2:converter-jackson:2.0.0'
    // compile 'com.squareup.retrofit:converter-jackson:1.9.0'
    compile 'com.squareup.okhttp3:okhttp:3.3.1'
    compile 'com.github.johnkil.android-appmsg:appmsg:1.2.0'
    compile 'me.zhanghai.android.materialprogressbar:library:1.1.6'
    compile('com.github.afollestad.material-dialogs:core:0.8.5.8@aar') {
        transitive = true
    }
    compile 'com.github.nisrulz:easydeviceinfo:1.1.9'
    compile 'com.android.support:multidex:1.0.1'
    compile project(':projects:wifiConnecter')

    compile project(':projects:knoxActivator')
    provided files('libs/cdm.jar')
    provided files('libs/edm.jar')
    provided files('libs/knox.jar')
    provided files('libs/license.jar')
    provided files('libs/rc.jar')
}

我添加了 compileOptions 但再次出现异常。 你能帮帮我吗?

最佳答案

你改变了

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

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

关于Android 将字节码转换为 dex : Cause: Dex cannot parse version 52 byte code 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42578194/

相关文章:

android - 水平 ScrollView ,左右子元素显示一点

android - "Compatible side by side NDK version was not found. Default is 20.0.5594570."是什么意思?

android - 在我的 Android 应用程序中从前置摄像头录制时无法获得高 fps(每秒帧数)速率(大约 30fps)

android - 通过gradle使android github项目可用

android - 如何在每个构建中随机化 ProGuard 字典?

java - 坚持一些角度算术

java - 如何修改我的代码以使用前置摄像头扫描二维码

android - Eclipse/Android无法为任何项目生成R文件

android - 使用 ndk-gdb 调试时调用参数丢失。堆栈跟踪有效

安卓 TDD : The saga continues with Robolectric & Gradle