Gradle 失败可能是因为这个 Flutter 应用程序中的 AndroidX 不兼容 [英] The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app

查看:38
本文介绍了Gradle 失败可能是因为这个 Flutter 应用程序中的 AndroidX 不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从更新依赖类路径时会出现此问题'com.android.tools.build:gradle:3.2.1'*'com.android.tools.build:gradle:3.3.2'

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'

项目级 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
    }

应用级 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

推荐答案

在 android/gradle.properties 中添加:

add this in android/gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

参考:https://flutter.dev/docs/development/包和插件/androidx 兼容性

这篇关于Gradle 失败可能是因为这个 Flutter 应用程序中的 AndroidX 不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆