Open VincentSastra opened 2 weeks ago
I'm seeing this same error:
java.lang.NullPointerException: null cannot be cast to non-null type com.rncamerakit.CKCamera
at com.rncamerakit.RNCameraKitModule.capture$lambda$0(RNCameraKitModule.kt:70)
since upgrading to react-native@0.76
If this is a clue, it happens when I upgraded to the latest react native version which uses the "new architecture". Maybe this has something to do with it:
https://github.com/reactwg/react-native-new-architecture/discussions/201
I can confirm that this code works with the new architecture (current react-native version is 0.76.1), BUT I was not able to make it switch between old and new architecture:
import com.facebook.react.uimanager.UIManagerHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import com.facebook.react.BuildConfig
// (...)
@ReactMethod
fun capture(options: ReadableMap, viewTag: Int, promise: Promise) {
// if (ReactFeatureFlags.useTurboModules) {
// if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
captureUsingNewArchitecture(options, viewTag, promise)
// } else {
// captureUsingOldArchitecture(options, viewTag, promise)
// }
}
private fun captureUsingNewArchitecture(options: ReadableMap, viewTag: Int, promise: Promise) {
GlobalScope.launch(Dispatchers.Main) {
try {
val uiManager = UIManagerHelper.getUIManager(reactContext, viewTag)
val view = uiManager?.resolveView(viewTag) as? CKCamera
if (view != null) {
view.capture(options.toHashMap(), promise)
} else {
promise.reject("VIEW_NOT_FOUND", "Could not find CKCamera view with tag $viewTag")
}
} catch (e: Exception) {
promise.reject("CAPTURE_FAILED", e.message, e)
}
}
}
private fun captureUsingOldArchitecture(options: ReadableMap, viewTag: Int, promise: Promise) {
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
reactContext.runOnUiQueueThread {
val view = uiManager?.resolveView(viewTag) as? CKCamera
if (view != null) {
view.capture(options.toHashMap(), promise)
} else {
promise.reject("VIEW_NOT_FOUND", "Could not find CKCamera view with tag $viewTag")
}
}
}
Versions OS: Android 13 React: 18.3.1 React Native: 0.76.1 react-native-camera-kit: 14.0.0
Describe the bug App crash after capture, Logcat mentions two main errors
getOrCreateModule(): Unable to create module "UIManager" (legacy: false, turbo: true)
and thenjava.lang.NullPointerException: null cannot be cast to non-null type com.rncamerakit.CKCamera
at com.rncamerakit.RNCameraKitModule.capture$lambda$0(RNCameraKitModule.kt:70)
on lineval view = uiManager?.resolveView(viewTag) as CKCamera
I believe the main issue is that the UIManager is not created
To Reproduce
Logcat Crash message
Null pointer at source code