Does not compile with Qt6.2
Closed this issue · 26 comments
Although Qt6.2 now supports the equivalent functionality of Qt5's "androidextras" package, I note no ifdefs in the source code for supporting Qt6.2, resulting in compilation errors like:
18:14:47: Running steps for project QtAndroidToolsDemo...
18:14:48: Starting: "/opt/QtCo/6.2.0/android_arm64_v8a/bin/qmake" /usr/local/src/QtAndroidTools/QtAndroidToolsDemo/QtAndroidToolsDemo.pro -spec android-clang CONFIG+=qtquickcompiler
Project ERROR: Unknown module(s) in QT: androidextras
18:14:48: The process "/opt/QtCo/6.2.0/android_arm64_v8a/bin/qmake" exited with code 3.
Error while building/deploying project QtAndroidToolsDemo (kit: Android Qt 6.2.0 Clang arm64-v8a)
When executing step "qmake"
Although I started replacing headers, and qmake files to prevent this, e.g. for QtAndroidTools.pri:
equals(QT_MAJOR_VERSION, 6):greaterThan(QT_MINOR_VERSION,1) {
## For Qt6.2, AndroidExtras is now part of QtCore
}
else:equals(QT_MAJOR_VERSION, 5) {
QT += androidextras ##Qt5 only
}
else { ##Functionality not available at all in Qt 6.0, 6.1
error("Qt$$QT_VERSION is unsupported... (Qt5, or Qt>=6.2 are supported).")
}
And for various .h files:
#if (QT_VERSION < 0x060000) //Qt5
#include <QtAndroidExtras>
#elif (QT_VERSION < 0x060200)
//Qt6.0, 6.1 are unsupported...
#elif (QT_VERSION >= 0x060200) //Qt6.2
#include <QCoreApplication> //Qt>=6.2 QAndroidJniEnvironment and QAndroidJniObject in QCore
#endif /* (QT_VERSION < 0x060000) */
I noticed I would soon be wading into a sea of ifdefs if i continued, e.g. each instance of
QtAndroid::androidSdkVersion() becomes QNativeInterface::QAndroidApplication::sdkVersion() for 6.2
So I was wondering if I am duplicating work or if there are plans to support Qt6.2 now that the beta is available to see if such functionality will work for future open-source Android apps?
For example to cleanly handle such trivial API changes as above, perhaps define a common QTAT_QTANDROID which is defined as QNativeInterface::QAndroidApplication
for 6.2 and QtAndroid
for Qt5 and then replace all QtAndroid::androidSdkVersion()
with QTAT_QTANDROID::androidSdkVersion()
??
For details see:
https://doc-snapshots.qt.io/qt6-dev/qnativeinterface-qandroidapplication.html
https://bugreports.qt.io/browse/QTBUG-89482
https://bugreports.qt.io/browse/QTBUG-84382
https://github.com/qt/qtandroidextras
Hi
Yes, Qt 6 calls are not compatible with version 5. In mobile section a lot of changes has been made than the conde doesn't compile. To start the porting I want to wait the release of final version of 6.2 (actually) planned for 30.09.2021. However this is a project I work on my free time than the porting it might during a while. In add of this I'm currently not 100% sure Qt team make available all the Android calls from 5 to 6. I just need to try and check...
I believe the calls are intended to be 100% covered, and if there are shortcomings, the only hope of seeing a remedy that would allow release of QtAndroidTools-based open-source apps within the next year or two ... would be to have the problems highlighted ASAP during the beta period. So I'm hoping I can convince you to undertake this task prior to the final 6.2 release.
I'm willing to help. It seems to me the problem is a very tedious query-replace of the API and naming changes that were done. And this could be done with a number of techniques, from straight-up ifdefing every change; which will make the code look terrible, and in the limit, nearly double the line count. Or use a set of internal defines, e.g. QTAT_QTANDROID mentioned above, and have all the API references go through that kind of indirection.
What is the plan for existing QtAndroidTools-based apps on the PlayStore or other sites, once Qt6.2 is officially released? Isn't that also, legally, the end-date for any store-published open-source Qt5.15 apps using the open-source version of Qt?
It's not a problem of convince me, it's a problem to find the time to make the porting. As already said this is a project I work on my free time but I have also some other apps in developments that, currently, have more priority. Regarding the porting itself I was thinking to port all the code to 6 version without continue support of 5. That's mean all the future releases will work on version 6 only. This because it will take too much time to do and tests the change in both version and in add of this, also if 5.15 is a LTS the support, bugfixed updates are released to commercial user only...
What is the plan for existing QtAndroidTools-based apps on the PlayStore or other sites, once Qt6.2 is officially released? Isn't that also, legally, the end-date for any store-published open-source Qt5.15 apps using the open-source version of Qt?
I don't understand this point, can you clarify?
My understanding is that unless you go full lgplv3 including qtcreator and any tools used to publish to the play store, one must use the latest "LTS" version of Qt. As of now, that is Qt5.15, but when 6.2LTS officially comes out, that will need to be Qt6. Those wanting to continue with Qt5.15 would need to purchase a commercial support license, especially for those utilizing the latest precompiled QtCreator to publish apps to the play store.
I have somewhere some documents describing this more concisely and legalistically... note statements from the Qt Company have been scrubbed or made intentionally vague due to the huge developer backlash they've received from this announcement, including a pseudo-fork from KDE ... "We are making this change to encourage open-source users to quickly adopt new versions. This helps maximize the feedback we can get form the community and to emphasize the commercial support available to those with longer product life cycles that rely on a specific Qt version."
The corollary to this: if open source developers find shortcomings in the 6.2LTS android API, it would make good sense to have these shortcomings listed and scheduled for resolution prior to the 6.2.0LTS release date -- aka now.
I'm already encountering much confusion in attempting to port my own app.
For example the usual external storage permissions request at runtime API (e.g. https://falsinsoft.blogspot.com/2018/12/qt-request-android-app-permissions.html ) , is all now hidden inside a private header file
6.2.0/android_arm64_v8a/include/QtCore/6.2.0/QtCore/private/qjnihelpers_p.h :
Q_CORE_EXPORT PermissionsHash requestPermissionsSync(JNIEnv *env, const QStringList &permissions, int timeoutMs = INT_MAX);
Q_CORE_EXPORT PermissionsResult checkPermission(const QString &permission);
Q_CORE_EXPORT bool shouldShowRequestPermissionRationale(const QString &permission);
So it's not even clear how such basic necessities are to be implemented under 6.2.... (TODO: investigate application android:requestLegacyExternalStorage="true"
functionality in AndroidManifest.xml )
As such, I'm taking back my "I believe the calls are intended to be 100% covered" statement until I can figure out how to handle even such rudimentary android functionality.
Well, in my understand lpglv3 doesn't change so much for android app. The dynamic libraries are inside the apk that is basically a compressed file. Theoretically anyone can substitute with latest version of Qt libraries but, obviously, nobody will do it.
Regarding android permissions this is the reasons I said I'm not 100% sure all the "features" of Qt 5 will be ported to version 6. But I would to wait for the final 6.2 release because (maybe) this permission feature could be added before the final version. Theoretically from beta to final version should be only bugfix and not addition of new features but I followed part of the discussion on internal Qt team and it seems to me that not even they have much how to proceed.
(TODO: investigate application android:requestLegacyExternalStorage="true" functionality in AndroidManifest.xml )
Regarding this point you can find info here, this is one of my contributions to Qt libraries.
Thanks for your contribution and explanation regarding android:requestLegacyExternalStorage="true" !
Regarding my above concern about needing private header access to replicate qt5 androidextras functionality, note:
https://www.qt.io/blog/qt-extras-modules-in-qt-6
Changes to Qt Android Extras
Key functionality from the module has been brought over to other Qt modules.Clients that still rely on missing functionality can include the private header <QtGui/private/qtandroidextras_p.h> as a stopgap solution.
To enable private headers use QT += core-private with qmake, or add a project dependency to Qt::CorePrivate with CMake.
Very bad solution to use private headers since, because is an internal part, nobody can guarantee this will remain unchanged in the future releases.
By the way at the end of the page you linked:
The permission request APIs have been replaced by the cross-platform QCoreApplication::requestPermission() API.
However, it is clear that there is enough work to port the code to new version 6 and this is the reasons it will be too much complicated to keep compatibility with both 5 and 6 versions. In the time I'll do the porting version 5 it will no longer be supported.
That "bad solution" is what Qt is suggesting as "stopgap"...
The fact that it is a private header is their legal-out: that the API is guaranteed to change once they actually figure out the proper API in some future version. I'm certainly not happy with QtCo's clear lack of planning in removing working functionality that leaves such huge gaps in support of necessary android functionality.
Your plan to port to Qt6 and not be back-compatible with Qt5 makes sense. It would be good to leave a working Qt5 branch behind for those wanting back-compatibiliy and move to Qt6 on the main branch.
To show you an example regarding the difficult to do the porting before official 6.2 version will be releases in the note in my previous message as follow:
The permission request APIs have been replaced by the cross-platform QCoreApplication::requestPermission() API.
This note on contains the following link:
https://doc-snapshots.qt.io/qt6-dev/qcoreapplication.html#requestPermission
however in the linked page no information are present regarding the requestPermission() API right now. An error? The information are not present because final 6.2 version has not been released and this information could change?
Regarding create a Qt5 branch it could make sense only if these branch would be supported but as already said, the develop will continue for 6.2 only. Maybe if in the future some heavy bug in the existing code will come up a support branch could be created starting from the current commit.
Is there any development or work on Qt 6? At least for Admob services
Not yet. Version 6 is not ready for Android since it still miss the android permissions request part that is currently incomplete. Also Qt speech that is a very important module for some of my apps is not in plan to be ported to version 6 yet...
Not yet. Version 6 is not ready for Android since it still miss the android permissions request part that is currently incomplete. Also Qt speech that is a very important module for some of my apps is not in plan to be ported to version 6 yet...
Maybe you can implemente native "Android Text to speech" to fix that
Maybe you can implemente native "Android Text to speech" to fix that
Well, yes I could but, currently, I don't think move to version 6 will have some benefits yet. It's are still incomplete and I have no plan to move until all the current version 5 features will be ported on new version by Qt team.
I have and application running in Qt6 and i need some QtAndroidTools functionnality, i will migrate some functionnality in new branch
Well, while I can reach you, I want to ask. I left a comment under the blog post, but I guess you didn't see it. How can I do what you describe in your blog for Qt 6.2?
I'm so sorry if I'm doing it wrong by asking this here, it can be deleted from anyone.
Hi,
Unfortunately qt version 6 is still immature to use in android programming. A lot of features has not been ported yet and some other are incomplete. I didn't start to use for these reasons. However I don't understand your question. The provided example doesn't work with qt 6?
I tried applying the changes in Qt 6. My code is being built successfully, but I am getting such an error on the android side.
W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
I think the error is caused by this line
You have the error because the Init() function is not called. the reasons of this is the main app java activity is as follow:
public class AppActivity extends org.qtproject.qt5.android.bindings.QtActivity
As you can see it work with qt 5 and in case of new version 6 this java class is not loaded. I don't have installed the new version 6 than I don't know the new name of the java activity. You should look in the android examples a check the new java class name.
I start introducing Qt6 support
Well, while I can reach you, I want to ask. I left a comment under the blog post, but I guess you didn't see it. How can I do what you describe in your blog for Qt 6.2?
I'm so sorry if I'm doing it wrong by asking this here, it can be deleted from anyone.
this one is fixed in Qt 6.2.2
I start introducing Qt6 support
Have any update ?
In addition, when applications developed with QT are sent to the background and recalled on Android, the application resets itself. Can we integrate onResume events in android so that it can continue from where it left off?
I'm sorry I can't use my English well.
I start introducing Qt6 support
Have any update ?
In addition, when applications developed with QT are sent to the background and recalled on Android, the application resets itself. Can we integrate onResume events in android so that it can continue from where it left off?
I'm sorry I can't use my English well.
for this i need to check to be sure
In addition, when applications developed with QT are sent to the background and recalled on Android, the application resets itself. Can we integrate onResume events in android so that it can continue from where it left off?
You need to manage onResume event by create your own java file inside your app deriving the main Qt application class. For this problem QtAndroidTools library cannot help you.
Ported library to Qt 6.4.1
Note blog entry on new permissions handling in 6.5: https://www.qt.io/blog/permission-apis-in-qt-6.5. Note however
"For now this API are C++ only, but we're investigating QML APIs that provide the same functionality."
Also, although I was able to compile and install 6.4.1-based QtAndroidTools example, most of the functionality wasn't working on the device other than getting back APK info, etc.. I didn't have time to explore exactly where things are going wrong as I'm working on a different project at the moment. Is the status of this code "working" or just "compiles without error"??
Obviously I verified all features working with Qt 6.4.1 before made the commit. What does it means "wasn't work". Can you describe better the problem?