11

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
Zoe
  • 27,060
  • 21
  • 118
  • 148
jazzbpn
  • 6,441
  • 16
  • 63
  • 99

4 Answers4

19

add this in android/gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

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

dsalkamoses
  • 284
  • 1
  • 8
  • 1
    After adding the above lines to `android/gradle.properties` make sure to update the gradle dependencies in `app/build.gradle` such as: ``` dependencies { ... androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' ... ``` Ref: http://blog.wafrat.com/flutter-androidx-migration/ – Georgi Koemdzhiev Dec 08 '19 at 12:22
10

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.

viv
  • 6,158
  • 6
  • 39
  • 54
5

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

SilenceCodder
  • 2,874
  • 24
  • 28
0

Make sure all assets are in use .

then flutter pub get then flutter pub upgrade then flutter pup outdated.