https://blog.csdn.net/jiangyangll/article/details/99675406
报错信息:The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app
原因:AndroidX 不兼容
解决方案:
AndroidStudio中提示网址 https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this:
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
In android/build.gradle, replace:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
by
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
In android/gradle.properties, append
android.enableJetifier=true
android.useAndroidX=true
In android/app/build.gradle:
Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28.
Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:
In android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
by
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Finally, under dependencies {, replace
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
by
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Avoiding AndroidX
If you want or need to avoid migrating to AndroidX, you’ll need to pin your plugin dependencies in your pubspec.yaml to the last major version from before they were migrated.
These are the last available versions of all the flutter/plugins packages that are pre AndroidX:
android_alarm_manager: 0.2.3
android_intent: 0.2.1
battery: 0.3.0
camera: 0.2.9+1
cloud_firestore: 0.8.2+3
cloud_functions: 0.0.5
connectivity: 0.3.2
device_info: 0.3.0
firebase_admob: 0.7.0
firebase_analytics: 1.1.0
firebase_auth: 0.7.0
firebase_core: 0.2.5+1
firebase_database: 1.0.5
firebase_dynamic_links: 0.1.1
firebase_messaging: 2.1.0
firebase_ml_vision: 0.2.1
firebase_performance: 0.0.8+1
firebase_remote_config: 0.0.6+1
firebase_storage: 1.0.4
google_maps_flutter: 0.1.0
google_sign_in: 3.2.4
image_picker: 0.4.12+1
local_auth: 0.3.1
package_info: 0.3.2+1
path_provider: 0.4.1
quick_actions: 0.2.2
sensors: 0.3.5
share: 0.5.3
shared_preferences: 0.4.3
url_launcher: 4.1.0+1
video_player: 0.9.0
webview_flutter: 0.2.0
Note that this is not an exhaustive list of all Flutter plugins that use AndroidX, and the AndroidX dependency in your app might be coming from another plugin besides these.
修改后,仍然报错:根据提示查得 android / build.gradle 中 ext.kotlin_version不能低于 1.3.0
所以解决办法:
buildscript {
ext.kotlin_version = '1.3.0'
将版本更改为1.3.0,再次运行程序运行成功
————————————————
版权声明:本文为CSDN博主「JYliangliang」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jiangyangll/article/details/99675406