十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Flutter OHOS ohos应用编译相关问题

Flutter OHOS ohos应用编译相关问题 使用 Flutter 命令行编译构建应用报错问题现象使用flutter build hap --release命令行编译构建应用的时候报错hvigor ERROR:ENOENT:no such file or directory,stat xxx\ohos\entry\oh_modules\flutter_native_x86_64问题根因调试阶段有交替使用模拟器和真机设备使用了模拟器的缓存解决方案编译构建命令指定平台架构flutterbuildhap--release--target-platformohos-arm64手动删除项目里以下缓存文件ohos/ ├──.dart_tool├──.build├── ohos │ ├── entry/ │ │ ├── build │ │ ├── oh_modules │ └─ oh_modules重新执行编译构建命令flutter build hap --release拷贝或克隆其他 Flutter OH 项目到本地后无法运行问题现象从其他开发者或 Git 仓库拷贝/克隆 Flutter 项目后编译运行时报错排查步骤检查 Flutter OH 项目与本地 Flutter版本的兼容性打开项目pubspec.yaml文件查看 sdk版本environment:sdk:版本号终端执行flutter doctor查看本地 Flutter 环境版本看是否和项目版本兼容若不兼容需修改。删除pubspec.lock并重新获取依赖# Windowsdel pubspec.lock# macOS/Linuxrm pubspec.lockflutter clean flutter pubget说明pubspec.lcok是依赖锁定文件原项目的环境可能与你本地不同删除后让 pub 根据当前环境重新解析依赖版本。清理构建缓存flutter clean删除build/,dart_tool/,ohos/oh_modules,ohos/entry/build等缓存目录。配置别名简化日常开发的编译命令在环境变量配置文件中配置别名简化Flutter OpenHarmony化日常使用的命令windows, 使用Git Bash可以执行常见的linux命令。(使用方式鼠标右键点击文件管理器中的空白处左键点击 Git Bash Here)linux, 修改~/.bash_profile。mac, 修改~/.bash_profile, 并在~/.zshrc中加上source ~/.bash_profile。# --local-engine 参数可选指向自行编译的engine产物建议在 linux/mac 环境使用exportENGINE_DIR~/ohos/engineexportENGINE_DEBUG$ENGINE_DIR/src/out/ohos_debug_unopt_arm64exportENGINE_PROFILE$ENGINE_DIR/src/out/ohos_profile_arm64exportENGINE_RELEASE$ENGINE_DIR/src/out/ohos_release_arm64 aliasfbuildDflutter build hap --local-engine$ENGINE_DEBUG--debugaliasfbuildPflutter build hap --local-engine$ENGINE_PROFILE--profilealiasfbuildRflutter build hap --local-engine$ENGINE_RELEASE--releasealiasfrunDflutter run -d$(hdc list targets)--local-engine$ENGINE_DEBUG--debugaliasfrunPflutter run -d$(hdc list targets)--local-engine$ENGINE_PROFILE--profilealiasfrunRflutter run -d$(hdc list targets)--local-engine$ENGINE_RELEASE--release使用方式配置完成后重新打开终端窗口在flutter工程目录中即可使用别名编译或运行。flutter create hello--platformsohoscdhello# 编译debug版本fbuildD# 运行debug版本frunD应用编译成功安装后出现白屏的情况详见ohos运行相关问题应用编译报错flutter插件结构重构前的版本使用了重构后的插件库报错日志:Oops; flutter has exited unexpectedly:type Null is not a subtype oftypeListdynamicintypecast.解决方案:flutter_flutter更新到master或dev的最新版本。(45bd5e627e1f1e5f4d335f205781565f576acc60, 2024-05-10)Flutter编译插件时引入预编译so包so包未打入har包问题现象使用DevEco工具查看编译后的har包目录下未找到引入的so包导致功能调用异常问题分析so包放置的路径不对导致编译时未打入har包解决方案:可参考FFI插件开发文档中关于预编译so包的放置路径flutter pub get 依赖冲突报错报错日志Resolving dependencies... Because flutter_cache_manager 3.0.0-nullsafety.03.3.2depends on path_provider from hosted and flutter_cache_manager depends on path_provider from git, flutter_cache_manager 3.0.0-nullsafety.03.3.2forbidden. So bedause xxx depends on flutter_cache_manager3.3.1, version solving failed. pub get failed ...exitcode:1解决方案使用dependency_overrides消除依赖冲突。dependencies:flutter:sdk:flutterdependency_overrides:path_provider:git:url:https://gitcode.com/CPF-Flutter/flutter_packages.gitpath:packages/path_provider/path_providerpath_provider_ohos:git:url:https://gitcode.com/CPF-Flutter/flutter_packages.gitpath:packages/path_provider/path_provider_ohosflutter三方库依赖错误日志信息Error:error:AbiSpecificIntegerInt32is missing mappingforohos_arm64. Dart snapshot generator failed withexitcode254Target ohos_aot_profile_ohos-arm64 failed: Exception: AOT snapshotter exited with code254.问题分析这类报错一般是未使用OpenHarmony社区适配的三方库解决方案查看yaml文件的三方库依赖通过文档查找对应的三方库地址OpenHarmony平台已适配三方库The SDK license agreement is not accepted日志信息:hvigor install success. hvigor ERROR: Cause: The SDK license agreementisnotaccepted.问题分析ohos工程的结构还是api11的但是使用的sdk是api12的这种情况下就会出现这个报错信息。解决方案将ohos工程结构升级为api12。操作步骤DevEco-Studio - Migrate Assistant - 5.0.0 - MigrateDevEco-Studio - File - Project Structure - Compatible SDK - 5.0.0(12)通过flutter build hap -release 编译版本 会导致 app.json versionName 字段重置背景查看app.json 下的versionName 字段然后执行flutter build hap -release 编译版本进行出包。现象发现次字段 再次被重置1.0.0。原因当前规格目前默认build会使用这个版本号。解决需要指定versionName和versionCode可以在build指令时加上指定版本。参考flutter build hap --build-name4.0.3 --build-number10000应用编译报错flutter工程和依赖的插件工程不是在同一个磁盘日志信息:ohpm ERROR:Foundexception: xxxisnotinthe same filesystemasthecurrentproject, reached retrylimitornon retryable error encountered.问题分析flutter工程和依赖的插件工程不是在同一个磁盘这种情况下就会出现这个报错信息。解决方案Windows环境下flutter工程和依赖的插件工程需要在同一个磁盘。Note that you need plugins to import files that are not JavaScript日志信息: hvigor ERROR: Failed :entry:defaultCompileArkTS... hvigor ERROR: Unexpected token (Notethatyou need pluginstoimportfilesthatarenotJavaScript)问题分析DevEco Studio由低版本升级到高版本这种情况下就会出现这个报错信息。解决方案修改hvigor-config.json5配置文件{modelVersion:5.0.0,dependencies:{},properties:{ohos.nativeResolver:false}}DevEco工具同步或者运行Flutter新模板工程依赖的插件与SDK不在一个磁盘日志信息 hvigor ERROR: The srcPath isnotarelativepath: xxxx * Trythefollowing: Make surethesrcPathinthehvigorconfig.tsfileoftheproject isarelativepath.问题分析新模板工程编译构建中flutter-hvigor-plugin插件使用hvigorConfig.includeNode添加三方库源码作为节点relativePath无法生成跨磁盘的相对路径导致传入的参数srcPath为绝对路径。解决方案应用编译报错flutter工程和依赖的插件工程不是在同一个磁盘
返回列表