使用原生插件
<camerax ref="camerax" :style="[{height:screenHeight+'px',width:'750rpx'}]"></camerax>
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 15.3.2
HBuilderX类型: 正式
HBuilderX版本号: 4.56
手机系统: Android
手机系统版本号: Android 13
手机厂商: 小米
手机机型: Redmi K40
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
使用原生插件
<camerax ref="camerax" :style="[{height:screenHeight+'px',width:'750rpx'}]"></camerax>
正常调用插件
调用插件异常
同样的APP代码和原生插件代码使用4.56云打包基座和正式版后插件都不可用,用4.56离线打包试过没问题,之前在4.36云打包也没问题。
报错信息如下:
10:22:54.686 reportJSException >>>> exception function:callAddElement, exception:java.lang.NullPointerException:
Attempt to invoke virtual method 'com.taobao.weex.dom.WXAttr com.taobao.weex.ui.component.basic.WXBasicComponent.getAttrs()' on a null object reference
at com.taobao.weex.ui.RenderContextImpl.registerComponent(SourceFile:4)
at com.taobao.weex.ui.WXRenderManager.registerComponent(SourceFile:3)
at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(SourceFile:12)
at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(SourceFile:24)
at com.taobao.weex.bridge.WXBridgeManager.callAddElement(SourceFile:29)
at com.taobao.weex.bridge.WXBridge.callAddElement(SourceFile:1)
at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)
at com.taobao.weex.base.SystemMessageHandler.handleMessage(SourceFile:1)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.os.HandlerThread.run(HandlerThread.java:67)
dennyjiang (作者)
插件的package.json
{
"name": "camerax-plugin",
"id": "camerax-plugin",
"version": "0.0.2",
"description": "",
"_dp_type":"nativeplugin",
"_dp_nativeplugin":{
"android": {
"plugins": [
{
"type": "component",
"name": "camerax",
"class": "io.dcloud.uniplugin.CameraXComponent"
}
],
"hooksClass": "io.dcloud.uniplugin.AppHookProxy",
"integrateType": "aar",
"dependencies": [
"androidx.camera:camera-core:1.4.0",
"androidx.camera:camera-camera2:1.4.0",
"androidx.camera:camera-lifecycle:1.4.0",
"androidx.camera:camera-view:1.4.0"
],
"excludeDependencies": [],
"compileOptions": {
"sourceCompatibility": "1.8",
"targetCompatibility": "1.8"
},
"abis": [
"armeabi-v7a", "arm64-v8a"
],
"minSdkVersion": "23",
"useAndroidX": true,
"permissions": [
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" />",
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />"
],
"parameters": { }
},
"ios": {
"plugins": [{
"type": "component",
"name": "camerax",
"class": "CameraxComponent"
}],
"hooksClass": "AppHookProxy",
"frameworks": [],
"integrateType": "framework",
"embedSwift": true,
"deploymentTarget": "14.0",
"validArchitectures": [ "arm64", "armv7" ]
}
}
}
dennyjiang (作者)
从hb启动APP在Android logcat日志中看到有个错误日志在hb工具没打印,
使用Android Studio中离线打包调试 不会出现该错误。
WXComponentFactory Exception type:[camerax] java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at com.taobao.weex.ui.SimpleComponentHolder$ClazzComponentCreator.createInstance(SourceFile:18)
at com.taobao.weex.ui.SimpleComponentHolder.createInstance(SourceFile:1)
at com.taobao.weex.ui.component.WXComponentFactory.newInstance(SourceFile:23)
at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(SourceFile:11)
at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(SourceFile:24)
at com.taobao.weex.bridge.WXBridgeManager.callAddElement(SourceFile:29)
at com.taobao.weex.bridge.WXBridge.callAddElement(SourceFile:1)
at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)
at com.taobao.weex.base.SystemMessageHandler.handleMessage(SourceFile:1)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.lang.IllegalStateException: Method setCurrentState must be called on the main thread
at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.kt:296)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.kt:105)
at io.dcloud.uniplugin.CameraXComponent.<init>(CameraXComponent.java:90)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at com.taobao.weex.ui.SimpleComponentHolder$ClazzComponentCreator.createInstance(SourceFile:18)
at com.taobao.weex.ui.SimpleComponentHolder.createInstance(SourceFile:1)
at com.taobao.weex.ui.component.WXComponentFactory.newInstance(SourceFile:23)
at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(SourceFile:11)
at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(SourceFile:24)
at com.taobao.weex.bridge.WXBridgeManager.callAddElement(SourceFile:29)
at com.taobao.weex.bridge.WXBridge.callAddElement(SourceFile:1)
at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)
at com.taobao.weex.base.SystemMessageHandler.handleMessage(SourceFile:1)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.os.HandlerThread.run(HandlerThread.java:67)
dennyjiang (作者)
setCurrentState
方法需要在main线程中执行,但为何同样的代码在离线打包(4.36/4.56)以及4.56版本的云打包都没问题需要进一步定位原因。修改方法1:
将组件构造函数里面的lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
移动到initComponentHostView
方法中修改方法2:
修改为一下代码直接运行在main线程中ContextCompat.getMainExecutor(context).execute(() -> { lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED); });
dennyjiang (作者)
就是云端打包有问题, 本地离线打包没问题。代码和配置都没有改动,即使用插件的历史版本云打包也还是同样问题。 本地除了hb 从4.36更新到4.56没有其他变更,另外就是云端打包环境有变更。
2025-03-24 12:45
dennyjiang (作者)
更新了插件包,可以的话帮忙看下
2025-03-24 12:59