【问题标题】:Android Studio2.1.1-Error converting bytecode to dexAndroid Studio2.1.1-将字节码转换为dex时出错
【发布时间】:2016-10-10 19:52:21
【问题描述】:

当我尝试在 android 中启动我的应用程序时。 我收到以下错误

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.

在 build.gradle 我有以下内容

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "jejapps.conexionremota"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    targetCompatibility = 1.7
    sourceCompatibility = 1.7
}

JAVA_HOME,我有java文件夹的地址(C:\Program Files (x86)\Java\jdk1.7.0_55)

非常感谢大家

【问题讨论】:

  • "..is 由 library dependencies .." - 检查你的 libs 目录和 junit/那个 jbundle 的东西。其中之一是为 Java 8 编译的,不是您的应用程序或您的(主模块)gradle 文件导致此问题。
  • 我应该在哪里检查它是否为 java 8 编译? @zapl
  • 它要么在某处说明,要么很复杂:stackoverflow.com/questions/3313532/…
  • jbundle Build-Jdk: 1.6.0_29 junit Build-Jdk: 1.6.0_45 哪个版本的java? @zapl

标签: java android


【解决方案1】:

我通过在项目的 gradle 脚本(build.gradle)中添加跟随语句来解决这个问题:

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

所以,最后,我项目的build.gradle是这样的:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}
allprojects {
    repositories {
        jcenter()
    }
    tasks.withType(JavaCompile) {
        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 2018-04-09
    • 2017-02-27
    相关资源
    最近更新 更多