java - Android Studio2.1.1-字节码转dex报错

标签 java android

当我尝试在 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)

非常感谢大家

最佳答案

我通过在项目的 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
    }

}

关于java - Android Studio2.1.1-字节码转dex报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37738183/

相关文章:

java - 奇怪的(对我来说)循环错误

java - 地址已在使用 : JVM_Bind but no process is listed using port with netstat

XHTML 上出现 Java EE 404 错误,但 HTML 上没有

android - 如何删除 QCalendarWidget 中的选定日期矩形和小部件中的小图标

Android默认浏览器不滚动网页

java - Android:需要在自定义适配器 ListView 中保存复选框状态

java - Android - 滚动停止后如何滚动到 ScrollView 的开头或结尾?

android - Paypal Android SDK 保险库

java - 我无法应用 gradle 6.x 插件

java - 谷歌应用引擎电子邮件