How to fix AndroidX compatibility for Flutter in Android Studio?

6,845

Solution 1

Reading a lot on internet github y foud everyone solves this problem by upgrading libraries. I found there is a lot of recent versions of google_sign_in so try upgrading google_sign_in to 4.0.6

Solution 2

I had the same problem, after a week of searching and mixing some of the answers I found, this was the one that finally worked

Follow the guide in: https://pub.dev/packages/barcode_scan But do this modifications:

Edit your project-level build.gradle file to look like this:

buildscript {
    ext.kotlin_version = '1.3.30'
    ...
    dependencies {
        ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
...

Edit your app-level build.gradle file to look like this:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
...

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

And if when you compile the app says something about a difference between androidx appcompat 1.0.0 and 1.0.2 Go to your plugin build.gradle file and change on dependencies

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
...
}

Solution 3

Update your gradle.properties file with this:

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
Share:
6,845
Barracud Apps
Author by

Barracud Apps

Belgian company created in November 2018 developing internal mobile applications. Team : Pierre LAMOTTE Alexia SCOURNEAU Cédric LEGRAND Simon ROMAINVILLE Website Facebook YouTube Twitter Instagram RedBubble MyTip

Updated on December 13, 2022

Comments

  • Barracud Apps
    Barracud Apps over 1 year

    I'm getting this error when trying flutter build apk :

    *******************************************************************************************
    The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
    See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
    *******************************************************************************************
    Gradle task assembleRelease failed with exit code 1
    

    But I can make my code run directly on a phone or an emulator... I already created APK files with that project (and sent it to the stores). The last APK was created on 2019/07/17. Since then, I only added some data in lists.

    I already tried to compile in the same conditions than the last time then :

    • flutter clean, etc.;
    • Invalidating caches;
    • Downgrade Flutter version;
    • Downgrade Kotlin version;
    • Downgrade Gradle version;
    • Downgrade Gradle-wrapper's distribution URL.

    Here are my dependencies :

    dependencies:
      flutter:
        sdk: flutter
      cloud_firestore: any
      firebase_auth: any
      google_sign_in: ^3.2.4
      flutter_datetime_picker: 1.0.7
      numberpicker: any
      flutter_svg: any
      dio: any
      path_provider: any
      firebase_messaging: any
      charts_flutter: any
      barcode_scan: 1.0.0
      unity_ads_flutter: any
      progress_indicators:
    

    Gradle files :

    buildscript {
        ext.kotlin_version = '1.3.31'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.2'
            classpath 'com.google.gms:google-services:4.3.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    dependencies {
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.2.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        implementation 'com.google.firebase:firebase-core:17.0.1'
        implementation 'com.google.firebase:firebase-auth:18.1.0'
        implementation 'com.google.firebase:firebase-messaging:19.0.1'
        implementation 'com.google.android.gms:play-services-auth:17.0.0'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    

    [EDIT] I changed my computer. Might it be the issue reason ?

    [EDIT 2] SOLVED

    Steps:

    • Upgrade packages
    dependencies:
      flutter:
        sdk: flutter
      cloud_firestore: any
      firebase_auth: any
      google_sign_in: any
      flutter_datetime_picker: 1.0.7
      numberpicker: any
      flutter_svg: any
      dio: any
      path_provider: any
      firebase_messaging: any
      charts_flutter: any
      barcode_scan: 1.0.0
      unity_ads_flutter: any
      progress_indicators:
    
    • Copy all files in new project

    It looks like some files were corrupted or lost during transfers to my new computer

    • F-1
      F-1 over 4 years
    • creativecreatorormaybenot
      creativecreatorormaybenot over 4 years
      "The failure may have been because ..". You should find the actual Gradle error by running the task with --info.
    • Barracud Apps
      Barracud Apps over 4 years
      @F-1 : I followed the guide and looked for the most recent versions of implementations I needed on AndroidX's site.
    • Barracud Apps
      Barracud Apps over 4 years
      @creativecreatorormaybenot : No problem has been shown. Only warnings with automatically replaced obsolete calls
    • creativecreatorormaybenot
      creativecreatorormaybenot over 4 years
      @BarracudApps The Gradle errors are not shown when executing flutter build. You will have to manually debug the failing Gradle tasks. There should be enough information out there if you did not understand what I mean.
    • Barracud Apps
      Barracud Apps over 4 years
      @creativecreatorormaybenot : I tried ./gradlew tasks --info
    • creativecreatorormaybenot
      creativecreatorormaybenot over 4 years
      @BarracudApps I cannot debug it for you, but gradlew assembleRelease --info would be a start..
    • Barracud Apps
      Barracud Apps over 4 years
      @creativecreatorormaybenot : Sorry, I'm tired --' It showed that the problem comes from google_sign_in ``` > Task :google_sign_in:verifyReleaseResources FAILED Caching disabled for task ':google_sign_in:verifyReleaseResources' because: Build cache is disabled Task ':google_sign_in:verifyReleaseResources' is not up-to-date because: Task has failed previously. All input files are considered out-of-date for incremental task ':google_sign_in:verifyReleaseResources'. Unable do incremental execution: full task run ```
  • charli3B
    charli3B over 4 years
    Try to use fixed plugins resolution... there are some of those plugins that are pre AndroidX: • cloud_firestore: 0.8.2+3 • firebase_auth: 0.7.0 • google_sign_in: 3.2.4 • path_provider: 0.4.1 • firebase_messaging: 2.1.0 maybe with 'any' you are resolving a version of a plugin that doen't uses AndroidX
  • charli3B
    charli3B over 4 years
    Look here from the documentation: [link] (flutter.dev/docs/development/packages-and-plugins/…) "AndroidX can break a Flutter app at compile time in two ways: * The app uses an AndroidX plugin and its main build.gradle file has a compileSdkVersion below version 28. * The app uses both deprecated and AndroidX code at the same time. These problems must be fixed by either manually migrating the code to the same library, or downgrading to versions of the plugins that still use the original support libraries"
  • Barracud Apps
    Barracud Apps over 4 years
    I just tried to downgrade Kotlin version as you recommend but nothing changed. I seems like the problem comes from google_sign_in
  • Barracud Apps
    Barracud Apps over 4 years
    Nothing changes with fixed versions. Since now, I had no problem with any packages
  • Rene Lazo
    Rene Lazo over 4 years
    I had this problem was when I add to my flutter proyect the location plugin and upgrade the core to flutter 1.5.4. But can fix it whit those steps.