记录flutter项目报错及解决办法

1.https证书问题,之前请求接口域名证书是dv证书,更换的新域名配置了泛域名证书,导致dio证书验证出错

:DioError [DioErrorType.DEFAULT]: HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))

解决办法:dio验证强制返回true:

(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client){
  client.badCertificateCallback = (cert, host, port){
    return true;
  };
};

2.Android 5.0之前的版本(API level < 21)使用Dalvik runtime来执行代码,默认限制每个APK只能使用一个classes.dex文件,而DEX规范又将单个DEX文件内引用的方法总数限制为65536个,第三方引入过多函数超限

D8: Cannot fit requested classes in a single dex file (# methods: 75464 > 65536)

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

解决办法:在android/app/build.gradle配置中添加参数:1.defaultConfig内添加  multiDexEnabled true  2.dependencies内添加  implementation 'com.android.support:multidex:1.0.3'

3.集成高德地图插件安卓运行报错闪退:

E/flutter (14718): [ERROR:flutter/shell/platform/android/platform_view_android_jni_impl.cc(43)] java.lang.NoClassDefFoundError: Failed resolution of: Lcom/amap/api/location/AMapLocationClient;

E/flutter (14718): at com.amap.flutter.location.AMapFlutterLocationPlugin.setApiKey(AMapFlutterLocationPlugin.java:115)

E/flutter (14718): at com.amap.flutter.location.AMapFlutterLocationPlugin.onMethodCall(AMapFlutterLocationPlugin.java:38)

E/flutter (14718): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)

E/flutter (14718): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)

E/flutter (14718): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)

E/flutter (14718): at android.os.MessageQueue.nativePollOnce(Native Method)

E/flutter (14718): at android.os.MessageQueue.next(MessageQueue.java:336)

E/flutter (14718): at android.os.Looper.loop(Looper.java:174)

E/flutter (14718): at android.app.ActivityThread.main(ActivityThread.java:7356)

E/flutter (14718): at java.lang.reflect.Method.invoke(Native Method)

E/flutter (14718): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)

E/flutter (14718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

解决办法:在app/build.gradle文件的dependencies配置中添加相关sdk依赖,参考下图:

4.集成Firebase推送模拟器运行报错:

E/FirebaseMessaging: Failed to get FIS auth token
    java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
        at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@18.0.1:5)
        at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@18.0.1:8)
        at com.google.firebase.messaging.GmsRpc.setDefaultAttributesToBundle(GmsRpc.java:260)
        at com.google.firebase.messaging.GmsRpc.startRpc(GmsRpc.java:222)
        at com.google.firebase.messaging.GmsRpc.getToken(GmsRpc.java:180)
        at com.google.firebase.messaging.FirebaseMessaging.lambda$blockingGetToken$10$FirebaseMessaging(FirebaseMessaging.java:610)
        at com.google.firebase.messaging.-$$Lambda$FirebaseMessaging$1AYfBMlbEOJoTvXNS_TEZqpK2SY.start(Unknown Source:6)
        at com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(RequestDeduplicator.java:67)
        at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(FirebaseMessaging.java:606)
        at com.google.firebase.messaging.SyncTask.maybeRefreshToken(SyncTask.java:121)
        at com.google.firebase.messaging.SyncTask.run(SyncTask.java:91)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.0.0:2)
        at java.lang.Thread.run(Thread.java:920)
     Caused by: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
        at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:208)
        at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:530)
        at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:385)
        at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$2$FirebaseInstallations(FirebaseInstallations.java:374)
        at com.google.firebase.installations.-$$Lambda$FirebaseInstallations$VZq1h0TBcWNH8Y5yY86ujrFFyLo.run(Unknown Source:4)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920) 
Connected to process 8077 on device 'Nexus_6P_API_31 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/CompatibilityChangeReporter: Compat change id reported: 171979766; UID 99001; state: ENABLED
I/ocessService0:: Background concurrent copying GC freed 464(100KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1997KB/3995KB, paused 641us,141us total 2.841s
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/cr_ChildProcessService: Creating new ChildProcessService pid=8077
解决办法:需要配置vpn

5. List赋值问题,有一个map list变量,我用一个新的list变量接收,然后在修改新的list数据的时候发现,旧的list变量的内容也变了:

List list1 = [{'label': 'first name', 'value': 'Jack'}, {'label': 'last name', 'value': 'Gold'}];
List list2 = List.from(list1);
list2.last['valuee'] = 'Gould';
print('list1: $list1 \n list2: $list2');

// Console
flutter: list1: [{label: first name, value: Jack}, {label: last name, value: Gold, valuee: Gould}]
 list2: [{label: first name, value: Jack}, {label: last name, value: Gold, valuee: Gould}]

解决方案:

通过for循环方式添加:List list2;    for (var item in list1) {list2.add(item);}

通过json decode+encode组合:List list2 = List.from(json.decode(json.encode(list1)));

6. iOS端 Pod Install报错:[!] Invalid `Podfile` file: undefined method `exists?' for File:Class.

原因是ruby3.2删除了对 exists 的支持导致该问题

解决方案:

1)升级Flutter SDK

2)打开flutter目录下的这个文件:/flutter/packages/flutter_tools/bin/podhelper.rb,搜索到这一行内容:return [] unless File.exists? file_path 将其中的 exists 改为 exist

后续问题会持续补充...

当在Android Studio中切换Flutter SDK之后,有可能会遇到一些报错。以下是一些可能的报错以及它们的解决方法: 1. 缺少Flutter插件:如果Android Studio无法找到Flutter插件,请确保已正确安装Flutter插件。要安装插件,可以打开Android Studio的“设置”菜单,然后导航到“插件”部分。在该部分中,搜索“Flutter”,然后单击“安装”按钮。 2. 缺少相关依赖项:切换Flutter SDK可能会导致一些依赖项缺失。可以尝试运行“flutter doctor”命令来检查缺失的依赖项并解决它们。该命令将列出任何缺失的依赖项并提供修复建议。 3. Flutter版本冲突:如果Flutter SDK的版本与项目中所需的Flutter版本不兼容,则可能会发生冲突。在这种情况下,可以尝试更新或降低Flutter SDK的版本来与项目需求相匹配。可以通过在终端中运行“flutter upgrade”来更新Flutter SDK,并降级到特定版本可以使用“flutter version <version>”命令。 4. 缺少Flutter配置:有时候在切换Flutter SDK后,项目可能需要重新配置。请确保在项目的根目录中运行“flutter create .”命令,以重新生成Flutter配置文件。这将确保项目正确识别和使用新的Flutter SDK。 5. 其他错误:如果以上步骤无法解决问题,则可能存在其他错误。在这种情况下,建议查看错误消息以获取更具体的信息,并搜索相关错误来找到解决办法。可以在Flutter社区论坛、GitHub问题页面等地方寻求帮助,以获取更多定制化的错误解决方案。 总的来说,切换Flutter SDK可能会带来一些问题,但通过检查插件安装、缺失依赖项、版本冲突、重新配置项目以及查找特定错误的解决方法,通常可以解决这些问题。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值