'Flutter error: Execution failed for task ':app:compileDebugJavaWithJavac'

I try run on android and return this error.

I Aredy tried:

gradle.properties:

android.useAndroidX=true android.enableJetifier=true

build.gradle:

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true

my pubspec.yaml:

flutter_facebook_login: ^3.0.0 firebase_database: ^3.1.0 firebase_auth: ^0.15.0+1 cloud_firestore: ^0.12.11 url_launcher: ^5.2.7 google_maps_flutter: ^0.5.21+12 image_picker: ^0.6.2+1 firebase_storage: ^3.0.8 intl: ^0.16.0

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

  • 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.

  • Get more help at https://help.gradle.org

BUILD FAILED in 35s The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility. Building plugin cloud_firestore... The plugin cloud_firestore could not be built due to the issue above.


SOLUTION:

When you created the new project, did you select "androidX"? And are those versions the latest versions? (meaning, androidX compatible/requiring). if not sure, create a new project and make sure to select androidX, and change the sdk settings to 23/29 as above.



Solution 1:[1]

Edit: Solution was a combination of creating a new project with AndroidX selected and add the proper SDK versions to the gradle file. Possibly with using correct dependency versions.

To migrate to AndroidX, you need to set the SDK versions to 21 or higher. I recommend 23 because that removes some other issues as well.

compileSdkVersion 29

lintOptions {
    disable 'InvalidPackage'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example"
    minSdkVersion 23
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    // testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Solution 2:[2]

I recently encountered this error using Flutter 2.2.2, None of the above solutions worked for me.

First try basic commands like:

cd android && ./gradlew clean 
flutter clean

If it doesn't work:

set distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip in android/gradle/wrapper/gradle-wrapper.properties

if your gradle version is <= 6.7 (refer gradle issue)

Try basic commands and build again!

Solution 3:[3]

Solution

  1. flutter clean
  2. delete android/.gradle and run
  3. revert pubspec.lock and flutter pub get flutter run

Solution 4:[4]

None of answers above helped me. I use IntelliJ Idea as an IDE instead of Android Studio (because I develop other modules in other langs, not only Flutter app). I was able to run ./gradlew :app:compileDebugJavaWithJavac from command line, but flutter run failed. After long time I've realized that Flutter uses Android Studio to let it build android app. So if you use IntelliJ Idea, do check what Java you use not only in Idea (I use Java 11), but what Java you use in Android Studio! (mine AS used Java 8). After changing to Java 11, problem was solved.

Solution 5:[5]

Change compileSdkVersion value to flutter.compileSdkVersion also change minSdkVersion,targetSdkVersion values as shown below

android {
    compileSdkVersion flutter.compileSdkVersion

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.octs"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

This worked for me.

Solution 6:[6]

I solved my problem by changing the version (reduced the gradle version), which caused me another problem, but related to one API and Kotlin plugin. Since I cannot delete Kotlin I took out the API and it came to life again! thanks for your help here!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Karanjot Singh
Solution 3 Gaming buddy
Solution 4 Martin Edlman
Solution 5 cigien
Solution 6 ᴅ ᴇ ʙ ᴊ ᴇᴇ ᴛ