Godot Version
4.6.2.stable
Question
While i was working on a custom WebView node for Android using JavaClassWrapper node, i got these errors about a failure to find a class:
E 0:00:00:957 webview.gd:67 @ <anonymous lambda>(): Failed to find Java class: "com/android/webview/chromium/ContentSettingsAdapter".
<C++ Error> Parameter "class_object" is null.
<C++ Source> platform/android/jni_utils.cpp:600 @ jni_find_class()
<Stack Trace> webview.gd:67 @ <anonymous lambda>()
E 0:00:00:957 webview.gd:67 @ <anonymous lambda>(): Java class 'com.android.webview.chromium.ContentSettingsAdapter' not found.
<C++ Error> Parameter "bclass" is null.
<C++ Source> platform/android/java_class_wrapper.cpp:1474 @ _wrap()
<Stack Trace> webview.gd:67 @ <anonymous lambda>()
E 0:00:01:000 AndroidWebView.<anonymous lambda>: Invalid call. Nonexistent function 'getSettings' in base 'JavaObject'.
<GDScript Source>webview.gd:67 @ AndroidWebView.<anonymous lambda>()
<Stack Trace> webview.gd:67 @ <anonymous lambda>()
I have no idea if this is a Godot’s Java bridge bug or there is something wrong in my code.
The WebView works completely fine if i remove the getSettings call, but then i won’t be able to enable Javascript.
Code:
var android_runtime = Engine.get_singleton("AndroidRuntime")
var activity = android_runtime.getActivity()
var callable = func():
var WebView = JavaClassWrapper.wrap("android.webkit.WebView")
var WebViewClient = JavaClassWrapper.wrap("android.webkit.WebViewClient")
var LayoutParams = JavaClassWrapper.wrap("android.view.ViewGroup$LayoutParams")
webview_instance = WebView.WebView(activity)
webview_settings = webview_instance.getSettings() # line where error happens
_setup_webview_settings()
var webview_client = WebViewClient.WebViewClient()
webview_instance.setWebViewClient(webview_client)
var layout_params = LayoutParams.call("ViewGroup$LayoutParams", -1, -1)
webview_instance.setLayoutParams(layout_params)
var window = activity.getWindow()
var decor_view = window.getDecorView()
root_layout = decor_view.findViewById(0x01020002)
root_layout.addView(webview_instance)
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))