Andrioid Studio-将字节码转换为dex时出错,原因:Dex无法解析版本52字节码 [英] Andrioid Studio - Error converting bytecode to dex, Cause: Dex cannot parse version 52 byte code
问题描述
以下是我的android studio项目build.gradle的内容:
Below is the content of my build.gradle for an android studio project :
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
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 'net.time4j:time4j-calendar:4.20'
compile 'net.time4j:time4j-olson:4.0'
testCompile 'junit:junit:4.12'
}
bur我得到以下错误:
bur I get the below ERROR :
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.
如您所见,我已经尝试添加targetCompatibility和sourceCompatibility,但是问题仍然存在.
As you can see , I have already tried adding targetCompatibility and sourceCompatibility , but the issue persist.
我进行了搜索,似乎报告了类似的问题,但现在似乎尚未找到解决方案.
I searched and seems there are similar issues reported, but seems now yet find a solution for this.
推荐答案
我需要使用最新版本的time4j,因此不能选择返回Java 7版本的time4j lib. 我发现有一个针对time4j的姊妹项目,该项目是针对Andriod的,它称为time4a或time4j-android.因此,我按如下所示更改了build.gradle并解决了该问题:
I needed to use the latest version of the time4j , so going back to Java 7 versions of the time4j lib was not an option. I found out there is a sister project for time4j which is for Andriod, its called time4a or time4j-android . So I changed the build.gradle as follow and it solved the issue :
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'
这篇关于Andrioid Studio-将字节码转换为dex时出错,原因:Dex无法解析版本52字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!