Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle error set targetCompatibility t 1.7

i got this error message saying
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.

i tried to add targetCompatibility = '1.7'and sourceCompatibility = '1.7' inside the dependencies but it still gave me the same error,, how do i solve this?

(i just added mysql connector to my library and it automatically generated that dependency)

 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')

   }
like image 767
Boneyflesh Avatar asked Feb 11 '17 09:02

Boneyflesh


People also ask

Is Gradle 7 compatible with Java 8?

Compiling and testing Java 6/7Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7. Java 5 and below are not supported.

What Java version does Gradle support?

Java. A Java version between 8 and 18 is required to execute Gradle. Java 19 and later versions are not yet supported. Java 6 and 7 can still be used for compilation and forked test execution.

What is sourceCompatibility in build Gradle?

According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."


1 Answers

Solved this by adding this to app.gradle

defaultConfig {
    jackOptions {
        enabled true
    }
}
dexOptions {

}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
like image 64
Boneyflesh Avatar answered Sep 29 '22 23:09

Boneyflesh