Looking for ?

Translate

Solved - Execution failed for task :share_plus:compileDebugJavaWithJavac. > error: invalid source release: 17

Hello my co programmers, if you are facing this error or similar error, note that you're encountering, invalid source release: 17, typically happens when your Java version is not set correctly. 

This error indicates that the code you're compiling is targeting Java 17, but the version of Java used by your system is lower than that or incorrectly configured.

NOTE: share_plus or some other dependencies who act natively or work with phone hardware need java in other to work.

Here’s how you can resolve the issue: ensure you do all from No. 1 till No. 4

1. Run this command to check the current Java version:

java -version

OR

java --version


2. Set Java Version in Flutter:

You can configure your Flutter project to use Java 17 by adding the following to your android/build.gradle file:

android {

    compileOptions {

        sourceCompatibility JavaVersion.VERSION_17

        targetCompatibility JavaVersion.VERSION_17

    }

}


Also, make sure your gradle.properties file includes the following line:

org.gradle.java.home=/path/to/your/java17


NOTE: If you are on Macincloud or Mac PC, comment out the above line of code



3. Set Kotlin version: Open Android/build.gradle file

Locate buildscript {} section and update as below

buildscript {
    ext.kotlin_version = '1.8.0'  //What needed
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.0' 
}
}


4. Call the above kotlin through implementation: Open Android/app/build.gradle file
Locate dependencies  section and add the below line of code in it

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
  

SHARE THIS POST

About Wakabia

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment