热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

flutter2.1升级flutter3.0

下载最新fluttert版本forgithub

  1. 下载最新fluttert版本 for github

  2. 升级kotlin版本 及 gradle版本

Module was compiled with an
incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
Failed to apply plugin ‘kotlin-android’.
[ +4 ms] > The current Gradle version 6.7 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.7.1 or newer, or the previous version of the Kotlin plugin

更改build.gradle

buildscript {
ext.kotlin_version = '1.7.10' //改为更新版本
...
repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'} //改为https
...
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0' //改为更新版本
...

更改gradle-wrapper.properties

distributiOnUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip //改为更新版本

  1. 升级gradle后,需要更改maven下载源

Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public/)’ to redirect to asecure protocol (like HTTPS) or allow insecure protocols. See
https://docs.gradle.org/7.3.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

Could not resolve all dependencies for configuration ‘:app:debugRuntimeClasspath’
[ ] > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public)’ to redirect to a secure
protocol (like HTTPS) or allow insecure protocols. See

Could not resolve all dependencies for configuration ‘:adv_camera:androidApis’.
[ ] > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository ‘maven(http://maven.aliyun.com/nexus/content/groups/public)’ to redirect to a secure
protocol (like HTTPS) or allow insecure protocols. See
https://docs.gradle.org/7.3.3/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

$ vi ${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle
maven(http://maven.aliyun.com/nexus/content/groups/public/)
改为
maven(https://maven.aliyun.com/nexus/content/groups/public/)

  1. 修改pubspec.yml sdk版本
    支持null safe的flutter最低版本是2.0.0,对应的dart sdk是2.12.0

environment:
sdk: ">=2.12.0 <3.0.0" #改为2.12

  1. Gradle 7以后的版本是不可以用compile, 性能不如implementation

problem occurred evaluating project ‘:bluetooth_print’.
[ +1 ms] > Could not find method compile() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Could not run phased build action using connection to Gradle distribution ‘https://services.gradle.org/distributions/gradle-7.1.1-bin.zip’.
java.io.StreamCorruptedException: invalid type code: 00
invalid type code: 00Java(0)

尝试启动工程后,提示还有一些代码需要更改,一些包的升级以及业务代码中空安全的处理

  1. 一些小部件升级
  2. Scaffold.of(context).showSnackBar(…)

Try correcting the name to the name of an existing method, or defining a method named 'showSnackBar'.
[ ] [ ] Scaffold.of(context).showSnackBar(
[ ] [ ] ^^^^^^^^^^^^

改为
ScaffoldMessenger.of(context).showSnackBar(…)

  1. FlatButton 改为 TextButton
    参照 https://github.com/flutter/plugins/commit/a7dd76950e5b240d2d878504a6f010ef24717e34

Try correcting the name to the name of an existing method, or defining a method named 'FlatButton'.
[ ] [ ] FlatButton(
[ ] [ ] ^^^^^^^^^^

  1. RaisedButton 改为 ElevatedButton

Try correcting the name to the name of an existing method, or defining a method named 'RaisedButton'.
[ ] [ ] child: RaisedButton(
[ ] [ ] ^^^^^^^^^^^^

  1. WillPopScope#onWillPop返回true即退出

WillPopScope(
child: ... ,
onWillPop: () async {
// 点击返回键的操作
if(DateTime.now().difference(lastPopTime) > Duration(seconds: 1)){
lastPopTime = DateTime.now();
_gobackWebView();
}else{
lastPopTime = DateTime.now();
// 退出app
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
return true;
}

改为


WillPopScope(
child: ... ,
onWillPop: () async {
// 点击返回键的操作
if(DateTime.now().difference(lastPopTime) > Duration(seconds: 1)){
lastPopTime = DateTime.now();
_gobackWebView();
return false;
}else{
lastPopTime = DateTime.now();
return true;// 退出app
}
}

  1. AsyncSnapshot获取data
    AsyncSnapshot snapshot

final WebViewController cOntroller= snapshot.requireData;

改为

final WebViewController cOntroller= snapshot.data!;

  1. 更新permission_handler到最新版本,需要用新的方式获取权限

lib/sample.dart:402:11: Error: 'PermissionGroup' isn't a type.
Map permissiOns= await PermissionHandle

  1. 启动报如下错误
    A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps

注释掉

  1. 加了allowInsecureProtocol=true, 导致低版本的gradle报错

Launching lib\main.dart on AQM AL00 in debug mode...
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Script '${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle' line: 187
* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [class 'FlutterPlugin']
> Could not set unknown property 'allowInsecureProtocol' for object of type org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.

$ vi ${flutterRoot}\packages\flutter_tools\gradle\flutter.gradle
删除 allowInsecureProtocol=true

  1. 打开相机报错 Unexpected platform view context. When constructing a platform view in the factory, use the context from PlatformViewFactory#create, view id: 1

I/PlatformViewsController(24384): Hosting view in a virtual display for platform view: 1
E/flutter (24384): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Unexpected platform view context. When constructing a platform view in the factory, use the context from PlatformViewFactory#create, view id: 1
E/flutter (24384): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:187)
E/flutter (24384): at android.app.Dialog.dispatchOnCreate(Dialog.java:874)
E/flutter (24384): at android.app.Dialog.show(Dialog.java:521)
E/flutter (24384): at android.app.Presentation.show(Presentation.java:257)
E/flutter (24384): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:119)
E/flutter (24384): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:64)
E/flutter (24384): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:267)
E/flutter (24384): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/flutter (24384): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel1. o n M e t h o d C a l l ( P l a t f o r m V i e w s C h a n n e l . j a v a : 60 ) E / f l u t t e r ( 24384 ) : a t i o . f l u t t e r . p l u g i n . c o m m o n . M e t h o d C h a n n e l 1.onMethodCall(PlatformViewsChannel.java:60) E/flutter (24384): at io.flutter.plugin.common.MethodChannel1.onMethodCall(PlatformViewsChannel.java:60)E/flutter(24384):atio.flutter.plugin.common.MethodChannelIncomingMethodCallHandler.onMessage(MethodChannel.java:261)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue0 00io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:321)
E/flutter (24384): at io.flutter.embedding.engine.dart.DartMessenger$E x t e r n a l S y n t h e t i c L a m b d a 0. r u n ( U n k n o w n S o u r c e : 12 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . H a n d l e r . h a n d l e C a l l b a c k ( H a n d l e r . j a v a : 900 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . H a n d l e r . d i s p a t c h M e s s a g e ( H a n d l e r . j a v a : 103 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . o s . L o o p e r . l o o p ( L o o p e r . j a v a : 219 ) E / f l u t t e r ( 24384 ) : a t a n d r o i d . a p p . A c t i v i t y T h r e a d . m a i n ( A c t i v i t y T h r e a d . j a v a : 8668 ) E / f l u t t e r ( 24384 ) : a t j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( N a t i v e M e t h o d ) E / f l u t t e r ( 24384 ) : a t c o m . a n d r o i d . i n t e r n a l . o s . R u n t i m e I n i t ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (24384): at android.os.Handler.handleCallback(Handler.java:900) E/flutter (24384): at android.os.Handler.dispatchMessage(Handler.java:103) E/flutter (24384): at android.os.Looper.loop(Looper.java:219) E/flutter (24384): at android.app.ActivityThread.main(ActivityThread.java:8668) E/flutter (24384): at java.lang.reflect.Method.invoke(Native Method) E/flutter (24384): at com.android.internal.os.RuntimeInitExternalSyntheticLambda0.run(UnknownSource:12)E/flutter(24384):atandroid.os.Handler.handleCallback(Handler.java:900)E/flutter(24384):atandroid.os.Handler.dispatchMessage(Handler.java:103)E/flutter(24384):atandroid.os.Looper.loop(Looper.java:219)E/flutter(24384):atandroid.app.ActivityThread.main(ActivityThread.java:8668)E/flutter(24384):atjava.lang.reflect.Method.invoke(NativeMethod)E/flutter(24384):atcom.android.internal.os.RuntimeInitMethodAndArgsCaller.run(RuntimeInit.java:513)
E/flutter (24384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

改为官方camera,还有一些包的更新,如下

device_info: ^2.0.3
url_launcher: ^6.1.5
path_provider: ^2.0.11
permission_handler: ^10.0.0
shared_preferences: ^2.0.15
camera: ^0.10.0+1


推荐阅读
  • 数字图书馆近期展出了一批精选的Linux经典著作,这些书籍虽然部分较为陈旧,但依然具有重要的参考价值。如需转载相关内容,请务必注明来源:小文论坛(http://www.xiaowenbbs.com)。 ... [详细]
  • 今天我开始学习Flutter,并在Android Studio 3.5.3中创建了一个新的Flutter项目。然而,在首次尝试运行时遇到了问题,Gradle任务 `assembleDebug` 执行失败,退出状态码为1。经过初步排查,发现可能是由于依赖项配置不当或Gradle版本不兼容导致的。为了解决这个问题,我计划检查项目的 `build.gradle` 文件,确保所有依赖项和插件版本都符合要求,并尝试更新Gradle版本。此外,还将验证环境变量配置是否正确,以确保开发环境的稳定性。 ... [详细]
  • 本文整理了一份基础的嵌入式Linux工程师笔试题,涵盖填空题、编程题和简答题,旨在帮助考生更好地准备考试。 ... [详细]
  • 深入理解Redis中的字典实现
    本文详细介绍了Redis中字典的实现机制,包括其底层数据结构、哈希表与哈希节点的关系、元素添加方法及rehash操作的具体流程。 ... [详细]
  • LeetCode 1736: 替换隐藏数字获取最晚时间
    本文详细介绍了如何通过替换隐藏数字来获取最晚时间,适用于 LeetCode 1736 题目。 ... [详细]
  • MySQL初级篇——字符串、日期时间、流程控制函数的相关应用
    文章目录:1.字符串函数2.日期时间函数2.1获取日期时间2.2日期与时间戳的转换2.3获取年月日、时分秒、星期数、天数等函数2.4时间和秒钟的转换2. ... [详细]
  • 通过将常用的外部命令集成到VSCode中,可以提高开发效率。本文介绍如何在VSCode中配置和使用自定义的外部命令,从而简化命令执行过程。 ... [详细]
  • 本文介绍了如何利用 `matplotlib` 库中的 `FuncAnimation` 类将 Python 中的动态图像保存为视频文件。通过详细解释 `FuncAnimation` 类的参数和方法,文章提供了多种实用技巧,帮助用户高效地生成高质量的动态图像视频。此外,还探讨了不同视频编码器的选择及其对输出文件质量的影响,为读者提供了全面的技术指导。 ... [详细]
  • 服务器部署中的安全策略实践与优化
    服务器部署中的安全策略实践与优化 ... [详细]
  • 每年,意甲、德甲、英超和西甲等各大足球联赛的赛程表都是球迷们关注的焦点。本文通过 Python 编程实现了一种生成赛程表的方法,该方法基于蛇形环算法。具体而言,将所有球队排列成两列的环形结构,左侧球队对阵右侧球队,首支队伍固定不动,其余队伍按顺时针方向循环移动,从而确保每场比赛不重复。此算法不仅高效,而且易于实现,为赛程安排提供了可靠的解决方案。 ... [详细]
  • 基于Dubbo与Zipkin的微服务调用链路监控解决方案
    本文提出了一种基于Dubbo与Zipkin的微服务调用链路监控解决方案。通过抽象配置层,支持HTTP和Kafka两种数据上报方式,实现了灵活且高效的调用链路追踪。该方案不仅提升了系统的可维护性和扩展性,还为故障排查提供了强大的支持。 ... [详细]
  • Android中将独立SO库封装进JAR包并实现SO库的加载与调用
    在Android开发中,将独立的SO库封装进JAR包并实现其加载与调用是一个常见的需求。本文详细介绍了如何将SO库嵌入到JAR包中,并确保在外部应用调用该JAR包时能够正确加载和使用这些SO库。通过这种方式,开发者可以更方便地管理和分发包含原生代码的库文件,提高开发效率和代码复用性。文章还探讨了常见的问题及其解决方案,帮助开发者避免在实际应用中遇到的坑。 ... [详细]
  • 在 Kubernetes 中,Pod 的调度通常由集群的自动调度策略决定,这些策略主要关注资源充足性和负载均衡。然而,在某些场景下,用户可能需要更精细地控制 Pod 的调度行为,例如将特定的服务(如 GitLab)部署到特定节点上,以提高性能或满足特定需求。本文深入解析了 Kubernetes 的亲和性调度机制,并探讨了多种优化策略,帮助用户实现更高效、更灵活的资源管理。 ... [详细]
  • Netty框架中运用Protobuf实现高效通信协议
    在Netty框架中,通过引入Protobuf来实现高效的通信协议。为了使用Protobuf,需要先准备好环境,包括下载并安装Protobuf的代码生成器`protoc`以及相应的源码包。具体资源可从官方下载页面获取,确保版本兼容性以充分发挥其性能优势。此外,配置好开发环境后,可以通过定义`.proto`文件来自动生成Java类,从而简化数据序列化和反序列化的操作,提高通信效率。 ... [详细]
  • PCM1870A 16位低功耗立体声音频ADC,集成麦克风偏置与放大功能
    PCM1870A是一款16位低功耗立体声音频ADC,集成了麦克风偏置和放大功能。该器件具备高性能的模拟前端,支持立体声单端输入,并配备了可切换的单差分输入模式,适用于多种音频应用。 ... [详细]
author-avatar
yngbzl_165
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有