23

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.

1
  • try, flutter clean; flutter pub get Commented Mar 7, 2023 at 6:15

10 Answers 10

11

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"
}
5
  • ok, it's a common problem, but if it's not that, then we would need more information i think. Could you try making a new clean project and add one library at a time until it breaks maybe?
    – Jonas357
    Commented Dec 5, 2019 at 9:05
  • ok, i add facebook_login: 3.0.0 and run ok, so i add firebase_database: ^3.1.0 and throw this error: BUILD FAILED in 9s The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility. ✏️ Creating android/settings_aar.gradle... ✓ android/settings_aar.gradle created successfully. Building plugin firebase_core... Running Gradle task 'assembleAarRelease'... Finished with error: The plugin firebase_core could not be built due to the issue above. Commented Dec 5, 2019 at 13:51
  • 1
    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.
    – Jonas357
    Commented Dec 5, 2019 at 13:57
  • happy to help :)
    – Jonas357
    Commented Dec 6, 2019 at 14:10
  • if the problem still exists even after updating targetSdkVersion and compileSdkVersion. it's probably because of Java version. go to android studio and check for updates, then update it
    – Manas
    Commented Feb 15, 2022 at 12:22
8

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!

1
  • 2
    Upgrading the Gradle version to gradle-6.7.1-all.zip resolved this issue for me. Thank you. Commented Jul 20, 2021 at 6:03
6

Solution

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

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.

1

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.

1

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!

0

In my case it was the Java version. I downgraded JDK from 20 to 15.0.2 and worked.

0

I managed to address the issue with the "Task :stripe_android:compileDebugJavaWithJavac FAILED" error by implementing a solution in my project. I included the following dependency override in the configuration:

dependency_overrides:
  stripe_android: "9.5.0+1"

This modification proved effective for me. Feel free to test it in your setup and inform me if it resolves the issue on your end as well.

0

For me deleting android\app\src\main\java\io\flutter\app\FlutterMultiDexApplication.java solved the problem

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 4 at 8:15
-7

Try this package flutter_stripe: ^3.2.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.