Skip to content

qt bootstrap: provide the JNIEnv getter pyjnius and android need - #3403

Open
f321x wants to merge 2 commits into
kivy:developfrom
f321x:202610_qt_bootstrap_jnienv
Open

f321x wants to merge 2 commits into
kivy:developfrom
f321x:202610_qt_bootstrap_jnienv

Conversation

@f321x

@f321x f321x commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

For every bootstrap that is not sdl2/sdl3, the android recipe defines
SDL_ANDROID_GetJNIEnv as WebView_AndroidGetJNIEnv and pyjnius'
genericndkbuild_jnienv_getter.patch makes jnius call the same symbol. Both
then link against the bootstrap's main library: the android recipe via
ANDROID_MAIN_LIB, pyjnius via PYJNIUS_ANDROID_LIBMAIN.

The qt bootstrap builds libmain_.so from start.c alone, so nothing
defines that symbol and the references to it from android._android and
jnius cannot be resolved.

pyjniusjni.c, which defines it, was duplicated byte for byte in the webview
and service_only bootstraps. Move it next to start.c in common/ and list it
in the qt bootstrap's LOCAL_SRC_FILES. sdl2 and sdl3 do not list it in their
own Android.mk, so they never compile it and keep getting the JNIEnv from
SDL.

Qt reaches libmain_.so through QtLoader.loadMainLibrary(), which calls
System.load()/System.loadLibrary(), so the JNI_OnLoad in pyjniusjni.c runs
and caches the JavaVM.

f321x added 2 commits October 28, 2026 10:33
For every bootstrap that is not sdl2/sdl3, the android recipe defines
SDL_ANDROID_GetJNIEnv as WebView_AndroidGetJNIEnv and pyjnius'
genericndkbuild_jnienv_getter.patch makes jnius call the same symbol. Both
then link against the bootstrap's main library: the android recipe via
ANDROID_MAIN_LIB, pyjnius via PYJNIUS_ANDROID_LIBMAIN.

The qt bootstrap builds libmain_<abi>.so from start.c alone, so nothing
defines that symbol and the references to it from android._android and
jnius cannot be resolved.

pyjniusjni.c, which defines it, was duplicated byte for byte in the webview
and service_only bootstraps. Move it next to start.c in common/ and list it
in the qt bootstrap's LOCAL_SRC_FILES. sdl2 and sdl3 do not list it in their
own Android.mk, so they never compile it and keep getting the JNIEnv from
SDL.

Qt reaches libmain_<abi>.so through QtLoader.loadMainLibrary(), which calls
System.load()/System.loadLibrary(), so the JNI_OnLoad in pyjniusjni.c runs
and caches the JavaVM.
Nothing in the tree reads them. ndk-build only ever includes files named
Android.mk: the jni/Android.mk and jni/application/Android.mk entry points
use $(call all-subdir-makefiles), which globs */Android.mk, and no makefile
includes Android_static.mk by name.

They are leftovers from the SDL android-project template, and they could not
work as written anyway: webview's links an SDL2_static module into a
bootstrap that builds no SDL, sdl3's asks for an SDL3_static module that the
SDL3 sources do not define, webview and service_only name a YourSourceHere.c
that does not exist, and four of the five end in the mangled

    $(call import-module,SDL)LOCAL_PATH := $(call my-dir)

that SDL's own template already shipped with. Each new bootstrap has been
carrying the file forward since, most recently qt and sdl3.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 63.297%. remained the same — f321x:202610_qt_bootstrap_jnienv into kivy:develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants