Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app

This issue occurs when updating the dependencies classpath from 'com.android.tools.build:gradle:3.2.1' to *'com.android.tools.build:gradle:3.3.2'

project-level build.gradle

buildscript {
        repositories {
            google()
            jcenter()
        }

        dependencies {
            classpath 'com.android.tools.build:gradle:3.3.2'
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

app-level build.gradle

def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)
        }
    }

    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }

    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
    if (flutterVersionCode == null) {
        flutterVersionCode = '1'
    }

    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }

    apply plugin: 'com.android.application'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

    android {
        compileSdkVersion 28

        lintOptions {
            disable 'InvalidPackage'
        }

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

        buildTypes {
            release {
                signingConfig signingConfigs.debug
            }
        }
    }

    flutter {
        source '../..'
    }

    dependencies {
        testImplementation 'junit:junit:4.12'
    }

pubspec.yaml

dependencies:
flutter:
  sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
  sdk: flutter
flutter_svg: ^0.12.0
printing: ^2.0.0
image: ^2.0.7
like image 955
jazzbpn Avatar asked Mar 27 '19 04:03

jazzbpn


3 Answers

add this in android/gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

Ref: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

like image 187
dsalkamoses Avatar answered Sep 19 '22 23:09

dsalkamoses


It seems you are using a Flutter dependency which is not compatible to Androidx, Try to comment the recent dependency and re-run it, If it's work, Try to use the dependency that's compatible with Androidx

like image 33
SilenceCodder Avatar answered Sep 17 '22 23:09

SilenceCodder


I had the same issue, after checking these 2 links: https://flutter.dev/docs/deployment/android

and proguard. The only thing that worked for me was removing minifyEnabled true fom build.graddle.

Hope it help some one.

like image 42
viv Avatar answered Sep 21 '22 23:09

viv