Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Build static library *.so for Android. How?
Forum Updated to NodeBB v4.3 + New Features

Build static library *.so for Android. How?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on 23 Aug 2019, 16:29 last edited by bogong
    #1

    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.

    T 1 Reply Last reply 23 Aug 2019, 16:59
    1
    • B bogong
      23 Aug 2019, 16:29

      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.

      T Offline
      T Offline
      Tom_H
      wrote on 23 Aug 2019, 16:59 last edited by
      #2

      @bogong library.so is the shared object version. library.a is the static version, which is what you wanted. What's the problem?

      B 1 Reply Last reply 24 Aug 2019, 14:18
      0
      • T Tom_H
        23 Aug 2019, 16:59

        @bogong library.so is the shared object version. library.a is the static version, which is what you wanted. What's the problem?

        B Offline
        B Offline
        bogong
        wrote on 24 Aug 2019, 14:18 last edited by
        #3

        @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).

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bogong
          wrote on 24 Aug 2019, 14:54 last edited by bogong
          #4

          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.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 24 Aug 2019, 15:02 last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            1/5

            23 Aug 2019, 16:29

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved