Home > other >  flutter In VS Code show error when I hit flutter run on my real device
flutter In VS Code show error when I hit flutter run on my real device

Time:07-12

when i hit flutter run on my real device it show me error below.my code was work ok at first but now it stuck. Launching lib\main.dart on SM A307FN in debug mode...

FAILURE: Build failed with an exception.

  • Where: Build file 'C:\flutter_application_1\android\app\build.gradle' line: 24

  • What went wrong: A problem occurred evaluating project ':app'.

Failed to apply plugin 'com.android.internal.application'. Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing org.gradle.java.home in gradle.properties.

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 3s Running Gradle task 'assembleDebug'... 5.6s

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────┐ │ [!] You need Java 11 or higher to build your app with this version of Gradle. │ │ │ │ To get Java 11, update to the latest version of Android Studio on │ │ https://developer.android.com/studio/install. │ │ │ │ To check the Java version used by Flutter, run flutter doctor -v. │ └───────────────────────────────────────────────────────────────────────────────┘ Exception: Gradle task assembleDebug failed with exit code 1

CodePudding user response:

Uninstall JAVA version 11 and install 1.8 version it worked for me hope it will work for you too.

CodePudding user response:

Can you show this files (C:\flutter_application_1\android\app\build.gradle) content along with gradle.properties ?

In your project/android/app/build.gradle there will be few lines like below:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

if you want to use java 11 , install java 11 and try adding these lines and replacing the above configuration:

compileOptions {         
     sourceCompatibility JavaVersion.VERSION_11         
     targetCompatibility JavaVersion.VERSION_11   
}  

kotlinOptions {         
     jvmTarget = '11'     
}

and do vice-versa for otherwise

  • Related