Replacement for static_init_classes in a Qt6.4.1 qmake project - crash in QtBluetoothBroadcastReceiver.onReceive(...)
-
I am porting a qt5 android project to qt6. The project uses qmake, and builds a patched version of qtconnectivity and deploys it to the device.
When I try to connect to a bluetooth device, the app crashes in QtBluetoothBroadcastReceiver.onReceive(...).
public void onReceive(Context context, Intent intent) { synchronized (qtContext) { // <------------ crashes here because qtContext is null if (qtObject == 0) return; jniOnReceive(qtObject, context, intent); } }
Prior to Qt6.2, 'QtActivityDelegate::loadApplication(...)' would call 'setContext' for modules that don't need/have setActivity, such as
QtBluetoothBroadcastReceiver.java. After Qt6.2, this is not happening.Prior to Qt 6.2, AndroidManifest.xml supported the following metadata:
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>which would result in an entry like this in libs.xml in the generated apk:
<string name="static_init_classes">org.qtproject.qt.android.bluetooth.QtBluetoothBroadcastReceiver</string>'QtActivityDelegate::loadApplication(...)' would then call 'setContext' for modules that don't need/have setActivity, such as
QtBluetoothBroadcastReceiver.java.After qt6.2, this AndroidManifest metadata is no longer supported, and should be removed. (https://doc.qt.io/qt-6/android-manifest-file-configuration.html).
How do I tag the QtBluetoothBroadcastReceiver class with 'static_init_classes'?
I see the following comment in https://doc.qt.io/qt-6/qt6-buildsystem.html :
"Porting Qt Plugins and Additional Libraries
While qmake is still supported for building Qt applications, it can no longer be used to compile custom Qt plugins, or libraries that rely on internals from the Qt 5 build system. Such libraries or plugins must be ported to CMake for use with Qt 6. At the time of the release of Qt 6.0, the API for building custom Qt plugins or libraries is still in tech preview, which means that it may
still change in future versions. A public stable API will be made available in a later Qt 6 release."I am not sure whether this applies to my situation. I am using qmake to build a custom Qt library, but I'm not sure whether it relies on internals from the Qt5 build system.