【问题标题】:Android studio: Dex cannot parse version 52 byte codeAndroid studio:Dex 无法解析版本 52 字节码
【发布时间】:2017-11-04 08:12:18
【问题描述】:

每当我尝试编译时,我都会收到以下错误 -

错误:将字节码转换为 dex 时出错: 原因:Dex 无法解析版本 52 字节码。 这是由使用 Java 8 或更高版本编译的库依赖关系引起的。 如果您在库子模块中使用“java”gradle 插件,请添加 目标兼容性 = '1.7' 源兼容性 = '1.7' 到该子模块的 build.gradle 文件。

我的 build.gradle 文件如下-

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.example.sbcappium"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
packagingOptions {
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/notice'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license'
    exclude 'META-INF/license.txt'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
apply plugin: 'android'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'

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.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i'
testCompile 'junit:junit:4.12'
compile files('libs/cglib-nodep-3.2.4.jar')


compile files('libs/commons-exec-1.3.jar')
compile files('libs/commons-io-2.5.jar')
compile files('libs/commons-lang3-3.5.jar')
compile files('libs/commons-logging-1.2.jar')

compile files('libs/gson-2.8.0.jar')
compile files('libs/guava-21.0.jar')
compile files('libs/hamcrest-core-1.3.jar')


compile files('libs/htmlunit-driver-2.26.jar')

compile files('libs/httpcore-4.4.6.jar')
compile files('libs/httpmime-4.5.3.jar')
compile files('libs/java-client-5.0.0-BETA8.jar')

compile files('libs/jetty-io-9.4.1.v20170120.jar')
compile files('libs/jetty-util-9.4.1.v20170120.jar')
compile files('libs/jna-4.1.0.jar')

compile files('libs/junit-4.12.jar')

compile files('libs/phantomjsdriver-1.4.0.jar')
compile files('libs/sac-1.3.jar')
compile files('libs/selenium-server-standalone-3.4.0.jar')
compile files('libs/serializer-2.7.2.jar')
compile files('libs/websocket-api-9.4.3.v20170317.jar')
compile files('libs/websocket-client-9.4.3.v20170317.jar')
compile files('libs/websocket-common-9.4.3.v20170317.jar')
compile 'com.android.support:support-annotations:25.3.1'}

我已经尝试了以下链接中提供的所有解决方案,但对我没有任何帮助-

  1. Android: Dex cannot parse version 52 byte code
  2. Andrioid Studio - Error converting bytecode to dex, Cause: Dex cannot parse version 52 byte code

我的 build.gradle 文件有什么问题?请记住,我已根据上述两个链接中提供的解决方案对 gradle 文件进行了所有可能的更改。

【问题讨论】:

  • 将兼容性更改为 1.8 您有一个需要 1.8 的依赖项,但您正在尝试使用 1.7 进行编译
  • @MattClark - 我之前尝试过,但没用。
  • 什么方法没用?发生了什么?请逐字引用任何错误消息。
  • @OleV.V.我已经提供了上面出现的错误。每当我运行主 java 文件时,都会出现上述错误。
  • 嗯,这可能是关于java-client-5.0.0-BETA8,另见其build.gradle-file的编译设置它似乎是用Java-8编译的。

标签: android android-studio build.gradle


【解决方案1】:

请将此代码添加到您的 build.gradle

  compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

希望你的问题得到解决

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多