Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100233

Android broken project/wrong libraries linked when adding UiTools

    XMLWordPrintable

    Details

    • Platform/s:
      Android, macOS
    • Commits:
      c8621da852 (qt/qtbase/dev) c8621da852 (qt/tqtc-qtbase/dev) 582fbe1bec (qt/qtbase/6.3) 582fbe1bec (qt/tqtc-qtbase/6.3) 8bae3fb471 (qt/qtbase/6.2) 8bae3fb471 (qt/tqtc-qtbase/6.2)

      Description

      Adding UiTools as project dependency messes up project and android target tries to link host OS (macOS) qt libraries instead of android native ones. Depending on position of UiTools in CMake find_package project either fails to configure or switches some libs to native mac one instead of android ones.

       This fails to configure completely android project

      find_package(Qt6 COMPONENTS REQUIRED UiTools Core Widgets Network PrintSupport Svg Quick Qml QuickWidgets)
      

       and this configures project but wrong libs get linked into project

      find_package(Qt6 COMPONENTS REQUIRED Core Widgets UiTools Network PrintSupport Svg Quick Qml QuickWidgets)
      

       

      here is minimal repro CMakeLists.txt

        

      cmake_minimum_required(VERSION 3.20.0)
      project(android)
      
      find_package(Qt6 COMPONENTS REQUIRED Core Widgets UiTools Network PrintSupport Svg Quick Qml QuickWidgets)
      
      # just dummy lib
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp "int main() { return 0; }")
      add_library(simple SHARED ${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
      
      target_link_libraries(simple PRIVATE Qt6::Core Qt6::Widgets Qt6::Network Qt6::PrintSupport Qt6::Svg Qt6::Quick Qt6::Qml Qt6::QuickWidgets Qt6::UiTools)
      
      

       

      and I build this like:

       

      mkdir build && cd build
      cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=$QT_ANDROID_ROOT/lib/cmake/Qt6/qt.toolchain.cmake -DANDROID_SDK_ROOT="${ANDROID_SDK}" -DANDROID_NDK_ROOT="${ANDROID_NDK}" ..
      

      built error output:

       

       

      [1/1] Linking CXX shared library libsimple.so
      FAILED: libsimple.so
      : && /usr/local/share/android-sdk/ndk/23.0.7196353/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android23 --sysroot=/usr/local/share/android-sdk/ndk/23.0.7196353/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ -O2 -g -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined -shared -Wl,-soname,libsimple.so -o libsimple.so CMakeFiles/simple.dir/main.cpp.o  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6PrintSupport_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Svg_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6QuickWidgets_arm64-v8a.so  /Users/ivang/Qt/6.2.2/macos/lib/QtUiTools.framework/Versions/A/QtUiTools  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Quick_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6QmlModels_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Qml_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Network_arm64-v8a.so  /Users/ivang/Qt/6.2.2/macos/lib/QtOpenGLWidgets.framework/Versions/A/QtOpenGLWidgets  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Widgets_arm64-v8a.so  /Users/ivang/Qt/6.2.2/macos/lib/QtOpenGL.framework/Versions/A/QtOpenGL  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Gui_arm64-v8a.so  /Users/ivang/Qt/6.2.2/android_arm64_v8a/lib/libQt6Core_arm64-v8a.so  -llog  -pthread  /usr/local/share/android-sdk/ndk/23.0.7196353/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/23/libGLESv2.so  /usr/local/share/android-sdk/ndk/23.0.7196353/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/23/libEGL.so   -latomic -lm && :
      ld: error: /Users/ivang/Qt/6.2.2/macos/lib/QtUiTools.framework/Versions/A/QtUiTools: unknown file type
      ld: error: /Users/ivang/Qt/6.2.2/macos/lib/QtOpenGLWidgets.framework/Versions/A/QtOpenGLWidgets: unknown file type
      ld: error: /Users/ivang/Qt/6.2.2/macos/lib/QtOpenGL.framework/Versions/A/QtOpenGL: unknown file type
      clang++: error: linker command failed with exit code 1 (use -v to see invocation)
      ninja: build stopped: subcommand failed.
      

       

      so far as workaround I found modifying

      Qt/6.2.2/android_arm64_v8a/lib/cmake/Qt6/Qt6Config.cmake

       adding

      AND NOT "${module}" MATCHES "^UiTools$"

      around line 160 after followinf line

       AND NOT "${module}" MATCHES "^Tools$"

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            qtbuildsystem Qt Build System Team
            Reporter:
            ivang Ivan Golubovic
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes