Android Flutter AndroidX incompatibilities报错处理
报错信息:The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app原因:AndroidX 不兼容解决方案:AndroidStudio中提示网址https://flutter.dev/docs/development/packages-and-plugins/a...
报错信息: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.propertieschange the line starting withdistributionUrllike 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, appendandroid.enableJetifier=true android.useAndroidX=true -
In
android/app/build.gradle:Under
android {, make surecompileSdkVersionandtargetSdkVersionare at least 28. -
Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default
.gradlefiles make the following changes:In
android/app/build.gradletestInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"by
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" -
Finally, under
dependencies {, replaceandroidTestImplementation '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.3android_intent: 0.2.1battery: 0.3.0camera: 0.2.9+1cloud_firestore: 0.8.2+3cloud_functions: 0.0.5connectivity: 0.3.2device_info: 0.3.0firebase_admob: 0.7.0firebase_analytics: 1.1.0firebase_auth: 0.7.0firebase_core: 0.2.5+1firebase_database: 1.0.5firebase_dynamic_links: 0.1.1firebase_messaging: 2.1.0firebase_ml_vision: 0.2.1firebase_performance: 0.0.8+1firebase_remote_config: 0.0.6+1firebase_storage: 1.0.4google_maps_flutter: 0.1.0google_sign_in: 3.2.4image_picker: 0.4.12+1local_auth: 0.3.1package_info: 0.3.2+1path_provider: 0.4.1quick_actions: 0.2.2sensors: 0.3.5share: 0.5.3shared_preferences: 0.4.3url_launcher: 4.1.0+1video_player: 0.9.0webview_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,再次运行程序运行成功
更多推荐



所有评论(0)