下面是我的 build.gradle 的一个 android studio 项目的内容:
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'
}
但我得到以下错误:
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,但问题仍然存在。
我搜索了一下,似乎有类似的问题报告,但现在似乎还没有找到解决方案。
最佳答案
我需要使用最新版本的 time4j ,因此无法回到 Java 7 版本的 time4j 库。 我发现有一个针对 time4j 的姐妹项目,它是针对 Andriod 的,它被称为 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'
关于java - Android Studio - 将字节码转换为 dex 时出错,原因 : Dex cannot parse version 52 byte code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40645390/