引入uni-wifi插件在uni-app中打自定义基座报错
引入uni-wifi插件在uni-app中打自定义基座报错
操作步骤:
- 引用了uni-wifi插件,打自定义基座的时候报错
预期结果:
- 能正常打包
实际结果:
- 打包失败
bug描述:
- 引用了uni-wifi插件,打自定义基座的时候报错,报错信息如下
[HBuilder] 15:20:08.338 e: file://uni_modules/uni-wifi/utssdk/app-android/src/index.kt:286:90 Type mismatch: inferred type is Number but Int was expected
[HBuilder] 15:20:08.338
[HBuilder] 15:20:08.338 FAILURE: Build failed with an exception.
[HBuilder] 15:20:08.338
[HBuilder] 15:20:08.339 * What went wrong:
[HBuilder] 15:20:08.339 Execution failed for task ':uni_modules:uni-wifi:compileReleaseKotlin'.
[HBuilder] 15:20:08.339 > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
[HBuilder] 15:20:08.339 > Compilation error. See log for more details
[HBuilder] 15:20:08.339
[HBuilder] 15:20:08.339 * Try:
[HBuilder] 15:20:08.339 > Run with --stacktrace option to get the stack trace.
[HBuilder] 15:20:08.339 > Run with --info or --debug option to get more log output.
[HBuilder] 15:20:08.339 > Run with --scan to get full insights.
[HBuilder] 15:20:08.339
[HBuilder] 15:20:08.339 * Get more help at https://help.gradle.org
[HBuilder] 15:20:08.339
[HBuilder] 15:20:08.339 BUILD FAILED in 36s
信息表
| 项目属性 | 值 |
|---|---|
| 产品分类 | uniapp/App |
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | win11 |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 3.94 |
| 手机系统 | Android |
| 手机系统版本号 | Android 14 |
| 手机厂商 | 小米 |
| 手机机型 | 小米10 |
| 页面类型 | vue |
| vue版本 | vue3 |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
更多关于引入uni-wifi插件在uni-app中打自定义基座报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
更多关于引入uni-wifi插件在uni-app中打自定义基座报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在 uni-app 中引入 uni-wifi 插件并打自定义基座时,可能会遇到一些报错。以下是一些常见的错误及其解决方法:
1. 插件未正确引入
- 错误信息:
Module not found: Error: Can't resolve 'uni-wifi' - 解决方法:
- 确保
uni-wifi插件已经正确安装。可以通过以下命令安装:npm install uni-wifi --save - 在
pages.json或manifest.json中正确配置插件。
- 确保
2. 插件版本不兼容
- 错误信息:
TypeError: Cannot read property 'xxx' of undefined - 解决方法:
- 确保
uni-wifi插件的版本与uni-app的版本兼容。可以尝试更新uni-wifi插件到最新版本:npm update uni-wifi
- 确保
3. 自定义基座配置错误
- 错误信息:
Error: Custom base configuration is invalid - 解决方法:
- 确保在
manifest.json中正确配置了自定义基座。可以参考以下配置:{ "app-plus": { "distribute": { "android": { "customBase": true }, "ios": { "customBase": true } } } }
- 确保在
4. 插件未正确注册
- 错误信息:
Plugin 'uni-wifi' is not registered - 解决方法:
- 确保在
main.js或App.vue中正确注册了uni-wifi插件。可以参考以下代码:import UniWifi from 'uni-wifi' Vue.use(UniWifi)
- 确保在
5. 权限问题
- 错误信息:
Permission denied或Wifi access denied - 解决方法:
- 确保在
manifest.json中正确配置了权限。可以参考以下配置:{ "app-plus": { "distribute": { "android": { "permissions": [ "android.permission.ACCESS_WIFI_STATE", "android.permission.CHANGE_WIFI_STATE" ] }, "ios": { "permissions": [ "NSLocationWhenInUseUsageDescription" ] } } } }
- 确保在
6. 其他错误
- 错误信息:
Unknown error或其他未明确的错误 - 解决方法:
- 检查控制台输出的完整错误信息,根据错误信息进行排查。
- 可以尝试清除缓存并重新构建项目:
npm run clean npm run build

