Unresolved reference: resolveView

Lee young-jun
2 min readOct 25, 2023

--

When KICKGOING was using version of react-native prior to 0.66.
I encountered an issue from new version of camera library.

Android code in react-native-vision-camera couldn’t find resolveView method.

Determined to find a solution, I started tracing the origins of resolveView. It turns out that resolveView was introduced in React-Native version 0.66. However, KICKGOING was still using an older version, specifically 0.63.4.

While I’m not an Android expert, I know Java.
This led me to explore dynamic method calls as a potential solution.

Dynamic method calls involve invoking a method by its name without direct method access, which can be immensely helpful. The process looked something like this

object.call("resolveView", ...)

To utilize dynamic calls,, I had to use type reflection.

I first stored the manager into a variable.

var manager = UIManagerHelper.getUIManager(ctx, viewId)

Next, I identified the resolveView method by its name within the manager.

view = manager!!::class.members.firstOrNull{ it.name == "resolveView" }

Finally, I called the method with the required parameter.

?.call(viewId) as CameraView?

As I implemented this approach, I ran into an issue.

To employ Kotlin’s reflection capabilities, I needed to import kotlin-reflect.

android/build.gradle

implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

Full Modification

var view: CameraView? = null

try {
var manager = UIManagerHelper.getUIManager(ctx, viewId)
view = manager!!::class.members.firstOrNull{ it.name == "resolveView" }?.call(viewId) as CameraView?
} catch(e: Exception) {
//
}

if (view == null) {
try {
view = ctx?.currentActivity?.findViewById<CameraView>(viewId)
} catch(e: Exception) {
//
}
}

I submitted this as a PR long time ago, But library author closed my PR recently and said to me ‘please use V3’.

References

--

--

No responses yet