The Gradle failure may have been because of Androi

2020-08-19 04:52发布

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

3条回答
疯言疯语
2楼-- · 2020-08-19 05:13

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-08-19 05:21

add this in android/gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

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

查看更多
霸刀☆藐视天下
4楼-- · 2020-08-19 05:26

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

查看更多
登录 后发表回答