build.gradle error set targetCompatibility t 1.7

时间:2017-02-11 09:33:46

标签: android-studio android-gradle mysql-connector

我收到此错误消息说
错误:将字节码转换为dex时出错:原因:Dex无法解析版本52字节代码。这是由使用Java 8或更高版本编译的库依赖项引起的。如果您在库子模块中使用'java'gradle插件,请将targetCompatibility ='1.7'sourceCompatibility ='1.7'添加到该子模块的build.gradle文件中。

我试图在依赖项中添加targetCompatibility ='1.7'和sourceCompatibility ='1.7',但它仍然给了我同样的错误,我该如何解决?

(我刚刚将mysql连接器添加到我的库中,它会自动生成该依赖项)

 apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.boneyflesh.connectnapls"
    minSdkVersion 17
    targetSdkVersion 25
    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(include: ['*.jar'], dir: 'libs')
    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.1.0'
    testCompile 'junit:junit:4.12'
    compile files('libs/mysql-connector-java-5.1.38-bin.jar')

   }

1 个答案:

答案 0 :(得分:6)

通过将此添加到app.gradle

来解决此问题
defaultConfig {
    jackOptions {
        enabled true
    }
}
dexOptions {

}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}