Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

CMAKE_PREFIX_PATH is not working with Android



  • I have compiled Qt 5.15.2 from git for android (only for armeabi-v7a) and now I'm trying to compile my Qt5 app for Android. QtCreator used to compile to android just fine but stopped working cause QTCREATORBUG-23898. So i wanted to compile my app from terminal.

    Here is what I came up with:-

    export QT_ROOT=/path/to/qt/installation
    export THIS=/home/kol/untitled/build
    export ANDROID_API=21
    export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi
    
    export CMAKE_PREFIX_PATH=$QT_ROOT/lib/cmake/Qt5
    
    ls $CMAKE_PREFIX_PATH
    
    cmake -GNinja .. \
        -DANDROID_SDK=$ANDROID_HOME \
        -DCMAKE_ANDROID_NDK=$ANDROID_NDK \
        -DANDROID_NATIVE_API_LEVEL:STRING=$ANDROID_API \
        -DANDROID_ABI=armeabi-v7a \
        -DANDROID_STL=c++_shared \
        -DANDROID_TOOLCHAIN=clang \
        -DCMAKE_TOOLCHAIN_FILE:PATH=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
        -DCMAKE_CXX_COMPILER=$TOOLCHAIN$ANDROID_API-clang++ \
        -DCMAKE_C_COMPILER=$TOOLCHAIN$ANDROID_API-clang \
        -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH
        -DCMAKE_SYSTEM_NAME=Android \
        -DQT_QMAKE_EXECUTABLE=$QT_ROOT/bin/qmake \
        -DCMAKE_BUILD_TYPE=Release 
    
    

    this gives me following:-

    Qt5Config.cmake  Qt5ConfigVersion.cmake  Qt5ModuleLocation.cmake
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /optHDD/AndroidNDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    CMake Error at CMakeLists.txt:27 (find_package):
      Could not find a package configuration file provided by "QT" with any of
      the following names:
    
        Qt6Config.cmake
        qt6-config.cmake
        Qt5Config.cmake
        qt5-config.cmake
    
      Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
      a directory containing one of the above files.  If "QT" provides a separate
      development package or SDK, be sure it has been installed.
    
    
    -- Configuring incomplete, errors occurred!
    See also "/home/smit/untitled/build/CMakeFiles/CMakeOutput.log".
    You have changed variables that require your cache to be deleted.
    Configure will be re-run and you may have to reset some variables.
    The following variables have changed:
    CMAKE_CXX_COMPILER= /optHDD/AndroidNDK/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++
    
    -- Generating done
    CMake Warning:
      Manually-specified variables were not used by the project:
    
        ANDROID_SDK
    
    
    CMake Generate step failed.  Build files cannot be regenerated correctly.
    

    the ls command clealy shows Qt5Config.cmake exists in given CMAKE_PREFIX_PATH but cmake is still not finding it.



  • i have a some problem. Does anyone have any solution?



  • my build status
    variable and cmake command.

    cmake -DCMAKE_PREFIX_PATH=$QTDIR -DQT_DIR=$QTDIR -DQT_QMAKE_EXECUTABLE=$QTDIR/bin/qmake -DANDROID_ABI=arm64-v8a -DANDROID_BUILD_ABI_arm64-v8a=ON -DANDROID_BUILD_ABI_armeabi-v7a=ON -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake .
     in dir /root/worker/cmakeAndroid/AndroidCMakeBuilder/build (timeout 1200 secs)
     watching logfiles {}
     argv: b'cmake -DCMAKE_PREFIX_PATH=$QTDIR -DQT_DIR=$QTDIR -DQT_QMAKE_EXECUTABLE=$QTDIR/bin/qmake -DANDROID_ABI=arm64-v8a -DANDROID_BUILD_ABI_arm64-v8a=ON -DANDROID_BUILD_ABI_armeabi-v7a=ON -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake  .'
     environment:
      ANDROID_API_VERSION=30
      ANDROID_HOME=/root/snap/androidsdk/current/AndroidSDK
      ANDROID_NDK_ROOT=/root/AndroidSDK/ndk/21.3.6528147
      ANDROID_SDK_ROOT=/root/AndroidSDK
      HOME=/root
      JAVA_HOME=/usr
      LANG=C.UTF-8
      LD_LIBRARY_PATH=:/root/Qt/5.15.0//android//lib
      LESSCLOSE=/usr/bin/lesspipe %s %s
      LESSOPEN=| /usr/bin/lesspipe %s
      LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
      OLDPWD=/root/worker
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/root/Qt/5.15.0//android//bin
      PWD=/root/worker/cmakeAndroid/AndroidCMakeBuilder/build
      QTDIR=/root/Qt/5.15.0//android/
      SHLVL=2
      TERM=xterm-256color
      USER=root
      _=/usr/local/bin/buildbot-worker
      container=lxc
     using PTY: False
    -- ANDROID_PLATFORM not set. Defaulting to minimum supported version
    16.
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /root/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    using ccache in /usr/bin/ccache
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /root/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
     LIB_OUTPUT_DIR = /root/worker/cmakeAndroid/AndroidCMakeBuilder/build/Patronum/QuasarAppLib/build/Release
    -- buid type    Release
    -- Project      QuasarApp
    -- c compiler   /root/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
    -- cxx compiler /root/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
    -- build shared 
    -- qmake exec   /root/Qt/5.15.0//android//bin/qmake
    CMake Error at Patronum/QuasarAppLib/CMakeLists.txt:37 (find_package):
      Could not find a package configuration file provided by "QT" with any of
      the following names:
    
        Qt6Config.cmake
        qt6-config.cmake
        Qt5Config.cmake
        qt5-config.cmake
    
      Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
      a directory containing one of the above files.  If "QT" provides a separate
      development package or SDK, be sure it has been installed.
    
    
    -- Configuring incomplete, errors occurred!
    See also "/root/worker/cmakeAndroid/AndroidCMakeBuilder/build/CMakeFiles/CMakeOutput.log".
    program finished with exit code 1
    elapsedTime=0.466865
    

  • Lifetime Qt Champion

    Hi,

    The CMAKE_PREFIX_PATH should contain the path to where the Qt cmake files are located.



  • I find solution
    Your need to add qt path into CMAKE_FIND_ROOT_PATH variable.

    cmake -DCMAKE_FIND_ROOT_PATH=yuor/qt/path .
    

    i think that trouble in the android.toolchain.cmake file. This toolchain overwrite the CMAKE_PREFIX_PATH variable.