Flutter HarmonyOS鸿蒙Next项目导入三方库运行报错
Flutter HarmonyOS鸿蒙Next项目导入三方库运行报错
- 目前直接使用flutter create 创建的项目,不做任何操作可以运行在鸿蒙设备上
- 自己创建的plugin,通过path和git引入可正常运行
- 引入社区三方库出现报错问题
- 现在引入三个社区三方库
- fluttertoast运行正常
fluttertoast: git: https://gitee.com/openharmony-sig/flutter_fluttertoast
- permission_handler报错
permission_handler: git: url: https://gitee.com/openharmony-sig/flutter_permission_handler path: permission_handler 错误日志: > hvigor ERROR: 2 file found in 'lib/arm64-v8a/libflutter.so'. This may cause unexpected errors at runtime. - /Users/Ming/Desktop/flutter_ohos/ohos/entry/oh_modules/.ohpm/@ohos+flutter_ohos@file+oh_modules+.ohpm+@ohos+permission_handler_ohos@file+har+permission_handler_ohos.har+oh_modules+@ohos+permission_handler_ohos+libs+flutter.har/oh_modules/@ohos/flutter_ohos/libs/arm64-v8a/libflutter.so - /Users/Ming/Desktop/flutter_ohos/ohos/entry/libs/arm64-v8a/libflutter.so Detail: Rename the native compilation products of the module, or configure nativeLib in /Users/Ming/Desktop/flutter_ohos/ohos/entry/build-profile.json5. > hvigor ERROR: BUILD FAILED in 1 s 768 ms
- image_picker引入报错
image_picker: git: url: "https://gitee.com/openharmony-sig/flutter_packages.git" path: "packages/image_picker/image_picker" 报错日志: ERROR: Fetch local package error, /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/libs/flutter.har not found. ohpm install error. WARN: ArkTS:WARN: For details about ArkTS syntax errors, see FAQs > hvigor ERROR: Failed :ImagePickerOhos:default@LintArkTS... > hvigor ERROR: ArkTS lint errors. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ExifDataCopier.ets:17:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/FileUtils.ets:18:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerCache.ets:19:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerDelegate.ets:17:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerPlugin.ets:17:26 Cannot find module '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityAware' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerPlugin.ets:21:8 Cannot find module '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerPlugin.ets:25:8 Cannot find module '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerPlugin.ets:28:33 Cannot find module '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImagePickerPlugin.ets:48:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/ImageResizer.ets:20:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:16:34 Cannot find module '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:17:28 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/ByteBuffer' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:18:26 Cannot find module '@ohos/flutter_ohos/src/main/ets/plugin/common/MessageCodec' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:19:33 Cannot find module '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:20:33 Cannot find module '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:21:17 Cannot find module '@ohos/flutter_ohos/src/main/ets/util/Log' or its corresponding type declarations. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:596:32 Property 'readValue' does not exist on type 'ImagePickerApiCodec'. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:599:32 Property 'readValue' does not exist on type 'ImagePickerApiCodec'. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:601:45 Property 'readValue' does not exist on type 'ImagePickerApiCodec'. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec2/packages/image_picker/image_picker_ohos/ohos/ImagePickerOhos/src/main/ets/image_picker/Messages.ets:603:52 Property 'readValue' does not exist on type 'ImagePickerApiCodec'. ArkTS:ERROR File: /Users/Ming/.pub-cache/git/flutter_packages-4781b6679280ac1a8e01f9c3c225da91b8628ec
- fluttertoast运行正常
更多关于Flutter HarmonyOS鸿蒙Next项目导入三方库运行报错的实战教程也可以访问 https://www.itying.com/category-92-b0.html
问题1,2需要手动删除文件 lib/arm64-v8a/libflutter.so
问题3临时解决方案,手动复制flutter.har文件到指定目录下
image_picker/image_picker_ohos/ohos/ImagePickerOhos/libs/flutter.har
更多关于Flutter HarmonyOS鸿蒙Next项目导入三方库运行报错的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
在Flutter项目中集成鸿蒙Next时,导入三方库运行报错可能是由于以下原因:
-
依赖冲突:三方库可能依赖了与鸿蒙Next不兼容的版本,导致编译或运行时出错。检查
pubspec.yaml
文件中的依赖版本,确保所有依赖与鸿蒙Next兼容。 -
平台适配问题:三方库可能未针对鸿蒙Next进行适配,导致在鸿蒙平台上无法正常运行。查看三方库的官方文档或GitHub Issues,确认是否有鸿蒙平台的适配支持。
-
NDK或SDK配置错误:鸿蒙Next可能需要特定的NDK或SDK配置。确保
android/app/build.gradle
文件中的配置正确,并且使用了鸿蒙Next支持的NDK版本。 -
权限问题:某些三方库可能需要特定的权限,而鸿蒙Next的权限管理可能与Android不同。检查
AndroidManifest.xml
文件,确保所有必要的权限已经声明。 -
代码混淆或优化问题:鸿蒙Next可能对代码混淆或优化有特定的要求。检查
proguard-rules.pro
文件,确保没有误混淆或优化导致的问题。 -
资源文件冲突:三方库可能包含了与鸿蒙Next冲突的资源文件。检查
res
目录,确保没有重复或冲突的资源文件。 -
Flutter版本问题:Flutter版本可能与鸿蒙Next不兼容。确保使用的Flutter版本支持鸿蒙Next。
-
鸿蒙Next的API变更:鸿蒙Next的API可能与三方库依赖的API不一致,导致报错。查看鸿蒙Next的API文档,确认是否有变更影响三方库的运行。
解决这些问题需要具体分析报错信息,逐步排查并调整配置。
在Flutter项目中导入三方库时,如果运行报错,可能是由于以下原因导致的:
-
依赖冲突:检查
pubspec.yaml
文件中的依赖版本是否冲突,尤其是与鸿蒙Next系统相关的库。 -
兼容性问题:确保三方库与HarmonyOS Next兼容,部分库可能仅支持特定平台。
-
环境配置:确认Flutter和鸿蒙开发环境配置正确,SDK版本是否匹配。
-
编译错误:查看具体报错信息,可能是编译过程中的语法或配置问题。
建议根据报错信息逐步排查,必要时更新三方库或调整项目配置。