[英]Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code
我有一個非常奇怪的錯誤。 我使用 android studio 2.3。
首先請看我的gradle文件。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.example.name.webrtcwork"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
sourceSets.main {
jniLibs.srcDir 'libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}
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:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.myhexaville:smart-image-picker:1.0.4'
compile 'pub.devrel:easypermissions:1.1.3'
compile('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile files('libs/autobanh.jar')
compile files('libs/base_java.jar')
compile files('libs/libjingle_peerconnection.jar')
testCompile 'junit:junit:4.12'
}
項目清理和重建工作成功,但如果我想運行應用程序,我會收到這樣的錯誤。
錯誤:將字節碼轉換為 dex 時出錯:原因:Dex 無法解析 52 版字節碼。 這是由使用 Java 8 或更高版本編譯的庫依賴項引起的。 如果您在庫子模塊中使用 'java' gradle 插件,請將 targetCompatibility = '1.7' sourceCompatibility = '1.7' 添加到該子模塊的 build.gradle 文件中。
錯誤:1個錯誤; 中止
錯誤:任務“:app:transformClassesWithDexForDebug”的執行失敗。 com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/Hayk.Mkrtchyan/.android/build-cache/7fd66238e8a360302161a82746a2b9f0a2s/outputjar/ classes.jar' 到 '/Users/Hayk.Mkrtchyan/Desktop/WebRTCWork/app/build/intermediates/pre-dexed/debug/classes_547e5465c50bca12a58d5755bafa9d6a10538b52.jar'
好的,我嘗試了很多方法來解決問題,例如在我的構建文件中添加targetCompatibility = '1.7' sourceCompatibility = '1.7'
。 這行不通。
我不想添加 1.8 版,也不想將我的 android studio 版本升級到 3.0。 我該如何解決這個問題?
如果我添加 1.8 版並啟用插孔,它也會給出錯誤。
錯誤:任務“:app:transformClassesWithPreJackPackagedLibrariesForDebug”的執行失敗。 無法從構建工具加載 Jill。
我怎樣才能解決這個問題?
錯誤:將字節碼轉換為 dex 時出錯:原因:Dex 無法解析 52 版字節碼。 這是由使用 Java 8 或更高版本編譯的庫依賴項引起的。 如果您在庫子模塊中使用 'java' gradle 插件,請將 targetCompatibility = '1.7' sourceCompatibility = '1.7' 添加到該子模塊的 build.gradle 文件中。
供參考
com.android.support:
版本應該相同。 Android Studio 3.0 及更高版本支持所有 Java 7 語言功能和 Java 8 語言功能的一個子集,這些功能因平台版本而異。 也可以直接在對應的build.gradle
文件中進行配置:
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
謝謝大家的回答。 問題是這個庫( compile 'com.myhexaville:smart-image-picker:1.0.4'
)產生了沖突。 當我刪除它時,一切終於奏效了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.