Can Qt be built statically for Android?
-
wrote on 16 Sept 2022, 20:52 last edited by
So, I created a static build of Qt using the android ndk/sdk and all that.
upon linking my app, I get a linker error;
ld: error: duplicate symbol: JNI_OnLoad >>> defined at androidjnimain.cpp:920 (/home/builds/qtbase/src/plugins/platforms/android/androidjnimain.cpp:920) >>> androidjnimain.cpp.o:(JNI_OnLoad) in archive /opt/android-qt6/./plugins/platforms/libqtforandroid_arm64-v8a.a >>> defined at qjnihelpers.cpp:435 (/home/builds/qtbase/src/corelib/kernel/qjnihelpers.cpp:435) >>> qjnihelpers.cpp.o:(.text.JNI_OnLoad+0x0) in archive /opt/android-qt6/lib/libQt6Core_arm64-v8a.a clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
I'm not sure if this is considered a bug (could be, they are both in qt-base), or maybe static linking Qt is simply not supported on Android.
Alternatively, maybe I should tweak the build..Anyone know more about this topic?
The error above is from Qt631.
-
wrote on 4 Oct 2022, 13:17 last edited by
https://developernote.com/2021/12/building-static-qt-for-android/
This guy tried a bunch of things but it didn't work, so looks like its not supported.
-
wrote on 3 Oct 2022, 07:10 last edited by
I'm not sure the current status of static building on Android. From this bug, it seems that the only potentially supported static linking would be for qtbase (qt core only). If you're trying to build Qt statically with multiple modules, it will certainly not work, because each module contains separate JNI_Onload's, that can't be automatically combined into one.
-
wrote on 3 Oct 2022, 08:48 last edited by
I got it to build Core, Gui, etc, with this configure command. But the resulting .a file (For QtCore) is about 200mb, which seems insane.
configure -static -prefix C:/Temp/android/ -android-ndk %ANDROID_NDK_ROOT% -android-sdk %ANDROID_SDK_ROOT% -no-rpath -release -platform android-clang -nomake tests -nomake examples -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -qt-host-path ../ -skip qtimageformats -skip qtlanguageserver -skip qtshadertools -skip qtsvg -skip qtdeclarative -skip qtmultimedia -skip qt3d -skip qt5compat -skip qtactiveqt -skip qtcharts -skip qtcoap -skip qtconnectivity -skip qtdatavis3d -skip qttools -skip qtdoc -skip qtlottie -skip qtmqtt -skip qtnetworkauth -skip qtopcua -skip qtpositioning -skip qtquicktimeline -skip qtquick3d -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtvirtualkeyboard -skip qtwayland -skip qtwebsockets -skip qtwebchannel -skip qtwebengine -skip qtwebviews -android-abis x86_64
android-abis you'll have to set according to your preference, as well as setting the envvars I included (This is windows-style env-var expansion)
-
wrote on 4 Oct 2022, 13:17 last edited by
https://developernote.com/2021/12/building-static-qt-for-android/
This guy tried a bunch of things but it didn't work, so looks like its not supported.
-
wrote on 4 Oct 2022, 20:46 last edited by JoeCFD 10 Apr 2022, 20:47
If you develop apps for Android, you can do it on Linux with prebuilt qt libs for Android which will be packed into your apks automatically. Why do you need to build them by yourself?
-
If you develop apps for Android, you can do it on Linux with prebuilt qt libs for Android which will be packed into your apks automatically. Why do you need to build them by yourself?
wrote on 14 Oct 2022, 17:01 last edited by@JoeCFD said in Can Qt be built statically for Android?:
If you develop apps for Android, you can do it on Linux with prebuilt qt libs for Android which will be packed into your apks automatically. Why do you need to build them by yourself?
By 'prebuilt qt libs', you mean .so (dynamic libraries) or .a (static libs)?