Build static library *.so for Android. How?
-
wrote on 23 Aug 2019, 16:29 last edited by bogong
Hello all!
I am writing static library on Qt. There are Qt Project defined like:
QT -= gui TEMPLATE = lib CONFIG += staticlib
And everything OK for iOS. There are building library.a file for iOS. But not building library.so for Android, it's building the same file library.a too. Where to define it for building correct library.so file exactly for Android? I am working on Mac OS.
-
Hello all!
I am writing static library on Qt. There are Qt Project defined like:
QT -= gui TEMPLATE = lib CONFIG += staticlib
And everything OK for iOS. There are building library.a file for iOS. But not building library.so for Android, it's building the same file library.a too. Where to define it for building correct library.so file exactly for Android? I am working on Mac OS.
wrote on 23 Aug 2019, 16:59 last edited by@bogong library.so is the shared object version. library.a is the static version, which is what you wanted. What's the problem?
-
@bogong library.so is the shared object version. library.a is the static version, which is what you wanted. What's the problem?
wrote on 24 Aug 2019, 14:18 last edited by@tom_h I don't know why but when I am building static in iOS everything works fine but on Android application crashed. I am trying to understand why it is and solve this issue. I've been always developing mono-block applications when everything is in one project. For now I am trying to separate UI and backend UI - Qt Quick Application, backend - static libraries *.a file. I thought that is because of static *.a (it's only my suggestions based on some libraries like openSSL and curl they build for iOS *.a files and for Android *.so).
-
wrote on 24 Aug 2019, 14:54 last edited by bogong
Solution found. If you need something like described above look below for getting steps that work for me:
- Define building static *.a for iOS/MacOS and shared *.so for Android in one backend project. Something like this:
QT -= gui TARGET = Library TEMPLATE = lib ios { CONFIG += staticlib } macos { CONFIG += staticlib }
- In the UI Qt Quick Application define separately for each platform the library. Something like this:
ios { LIBS += -L$$PWD/../Libs/ios/ -lLibrary PRE_TARGETDEPS += $$PWD/../Libs/ios/libLibrary.a } android { QMAKE_LINK += -nostdlib++ equals(ANDROID_TARGET_ARCH,arm64-v8a) { LIBS += -L$$PWD/../Libs/android_arm64-v8a/ -lLibrary ANDROID_EXTRA_LIBS += $$PWD/../Libs/android_arm64-v8a/libLibrary.so } equals(ANDROID_TARGET_ARCH,armeabi-v7a) { LIBS += -L$$PWD/../Libs/android_armeabi-v7a/ -lLibrary ANDROID_EXTRA_LIBS += $$PWD/../Libs/android_armeabi-v7a/libLibrary.so } equals(ANDROID_TARGET_ARCH,x86) { LIBS += -L$$PWD/../Libs/android_x86/ -lLibrary ANDROID_EXTRA_LIBS += $$PWD/../Libs/android_x86/libLibrary.so } } macos { LIBS += -L$$PWD/../Libs/macos/ -lLibrary PRE_TARGETDEPS += $$PWD/../Libs/macos/libLibrary.a } simulator { LIBS += -L$$PWD/../Libs/macos/ -lLibrary PRE_TARGETDEPS += $$PWD/../Libs/macos/libLibrary.a }
I don't know why but static library *.a built from Qt project not working on Android. Only shared library project working for Android therefore need to separate it at time of building. I am building it on MacOS. Maybe on other OS different.
-
AFAIK, that's because how the application has to be loaded on Android. It's a dynamic library that is loaded from the Java part.
1/5