2016-06-10 61 views
1

當我嘗試在android中啓動我的應用程序時。 我得到以下錯誤的build.gradleAndroid Studio2.1.1 - 將字節碼轉換爲dex時出錯

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. 

我有以下

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的地址:\程序文件(x86)\ Java的\ jdk1.7.0_55)

非常感謝你的所有

+0

「..是由*庫的依賴* ..引起」 - 檢查你的庫目錄和JUnit /那jbundle事。其中之一是針對Java 8編譯的,它不是導致此問題的應用程序或您的(主模塊)gradle文件。 – zapl

+0

http://oi65.tinypic.com/s2ur1x.jpg 那裏? –

+0

我應該在哪裏檢查它是否爲java 8編譯? @zapl –

回答

2

我解決這個問題,通過增加後續報表項目的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 
    } 

} 
+0

是的,爲我工作。謝謝 –

相關問題