Andrioid Studio - 将字节码转换为dex时出错,原因:Dex无法解析版本52字节的代码

时间:2016-11-17 01:44:07

标签: java android android-studio android-gradle

以下是我的build.gradle for android studio项目的内容:

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.

bur我得到以下错误:

For LastRow = 2 To Worksheets("Sheet1").Range("A65536").End(xlUp).Row
  Next LastRow
Range("A" & LastRow).ClearContents

如您所见,我已经尝试添加targetCompatibility和sourceCompatibility,但问题仍然存在。

我搜索并且似乎报告了类似的问题,但现在似乎找到了解决方案。

1 个答案:

答案 0 :(得分:1)

我需要使用time4j的最新版本,因此返回Java 7版本的time4j lib不是一个选项。 我发现有一个针对Andriod的time4j的姐妹项目,它叫做time4a或time4j-android。所以我改变了build.gradle,如下所示,它解决了这个问题:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.nariman.myapplication"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}
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:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i'
    testCompile 'junit:junit:4.12'
}

这条线解决了我的问题:

compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i'