The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
意思是 gradle失败可能因为AndroidX不兼容flutter app ,参考这个文档https://goo.gl/CP92wY去修复它
打开文档,说的很详细,大家有兴趣可以自己阅读,我这里做一下简单的解决
修复方式有两种
第一种:通过Android studio 迁移你的项目(推荐)
第一步:会打开一个新的Android项目的窗口
第二步:Android是 studio打开了一个新的Android窗口
在android项目里,setting-plugin,查看是否安装插件 Android support,如果没有去安装一下,一般应该都装了的
第三步:
以上我感觉这些设置默认的都没问题,可以不去修改。直接进行下面的操作。如果不行,再弄一下上面的
最重要的部分:迁移到AndroidX 很重要
一切ok,重新运行一下你的flutter项目吧
第二种:手动迁移你的项目(不推荐)
1.修改android/gradle/wrapper/gradle-wrapper.properties这个文件的像这样
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2.修改android/build.gradle文件
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
这个改成这个
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
3.修改这个文件android/gradle.properties
android.enableJetifier=true
android.useAndroidX=true
没有这两个请添加
4.这个文件里android/app/build.gradle
在 android { 里确保compileSdkVersion和targetSdkVersion是最新的28
5.在android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner
替换成
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dependencies { 里的
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
替换成
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
应该就可以了,因为这是不推荐的方法我就没去尝试,想去尝试的可以去试试。
最后:写博客不容易,一直以来觉得挺耽误时间,所以大家多多关注,谢谢