29

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

11 Answers 11

14

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"
}
Sign up to request clarification or add additional context in comments.

5 Comments

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?
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.
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.
happy to help :)
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
9

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 Comment

Based on new gradle version as of now, upgrading the Gradle version to gradle-8.10.2-all.zip resolved this issue for me.
7

Solution

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

Comments

6

For those facing a similar issue after upgrading to Android Studio Ladybug (2024), I solved the problem by downgrading my plugins in the settings.gradle as shown below:

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
id 'com.google.gms.google-services' version "4.3.15" apply false}

I'm using Gradle version 8.6. You can change it in gradle-wrapper.properties like below:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip

1 Comment

Downgrading is not a good solution..
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.

Comments

2

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.

Comments

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!

Comments

1
  1. In android/settings.gradle

before

id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false

after

id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.3.2" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
  1. In android/gradle/wrapper/gradle-wrapper.properties

before

distributionUrl=https://services.gradle.org/distributions/gradle-8.3-all.zip

after

distributionUrl=https://services.gradle.org/distributions/gradle-8.4-all.zip

Comments

-1

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

Comments

-1

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

1 Comment

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

For me, it was the google_fonts package, I removed it and it started working fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.