flutter开发中遇到的问题
Flutter 处理依赖冲突
当Flutter发生版本依赖冲突会有类似以下提示:
flutter_localizations any from sdk which depends on intl 0.15.8, intl 0.15.8 is required.
So, because env_pro_supervise depends on intl ^0.16.0, version solving failed.
我们只要在 pubspec.yaml 中将依赖改为相同版本。
如果是两个依赖的依赖冲突,不清楚当前到底应该使用依赖的哪一个版本时,我们可以使用any来解决版本依赖版本冲突的问题。由于不推荐使用any依赖,我们需要在pubspec.lock中找到正确的版本替换。
如果还是提示冲突,我们可以在 pubspec.yaml 添加以下内容,强制下载,忽略不兼容。
dependency_overrides:
intl: ^0.16.0
Flutter打包apk报错:Your app isn't using AndroidX.
对于此项目构建Apk提示问题,只需要添加两行代码即可解决。
在gradle.properties中添加如下代码即可:
android.enableJetifier=true
android.useAndroidX=true
flutter run后提示CachedNetworkImageProvider.load的异常,异常信息如下
Compiler message:
/D:/Software/Android/flutter/.pub-cache/hosted/pub.flutter-io.cn/cached_network_image-1.1.0/lib/src/cached_network_image_provider.dart:42:24: Error: The method 'CachedNetworkImageProvider.load' has fewer positional arguments than those of overridden method 'ImageProvider.load'.
ImageStreamCompleter load(CachedNetworkImageProvider key) {
^
/D:/Software/Android/flutter/packages/flutter/lib/src/painting/image_provider.dart:403:24: Context: This is the overridden method ('load').
ImageStreamCompleter load(T key, DecoderCallback decode);
解决方法:
打开pubspec.yaml文件,修改cached_network_image版本从原来的 1.1.0修改为2.0.0-rc,然后点击Packages get 完成后,重新运行,错误日志如下
Running "flutter pub get" in FlutterDouBan...
Because cached_network_image 2.0.0-rc depends on flutter_cache_manager ^1.1.2 and doubanapp depends on flutter_cache_manager 1.1.0, cached_network_image 2.0.0-rc is forbidden.
再次修改pubspec.yaml文件,把flutter_cache_manager版本更改1.1.2就可以
运行flutter run后提示androidx-annotations.pro异常,异常信息如下
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'
解决方法:
修改build.gradle打包的时候忽略掉 androidx-annotations.pro
android {
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
}