xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.89k stars 775 forks source link

Support Qt/Android build and deploy #404

Closed kassane closed 4 years ago

kassane commented 5 years ago

I am trying to compile for android the quickapp_qt project to test, but this occurs:

error:C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: fatal error: -f/--auxiliary may not be used without -shared clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

stack traceback: [C]: in function 'error' [C:\Program Files (x86)\xmake/core/base/os.lua:700]: in function 'raise' [C:\Program Files (x86)\xmake\core\sandbox\modules\os.lua:306]: in function 'runv' [C:\Program Files (x86)\xmake\modules\core\tools\gcc.lua:323]: [C]: in function 'link' [C:\Program Files (x86)\xmake\actions\build\kinds\binary.lua:93]: in function '_build_from_objects' [C:\Program Files (x86)\xmake\actions\build\kinds\binary.lua:152]: in function 'build' [C:\Program Files (x86)\xmake\actions\build\build.lua:40]: in function '_do_build_target' [C:\Program Files (x86)\xmake\actions\build\build.lua:64]: in function 'script' [C:\Program Files (x86)\xmake\actions\build\build.lua:140]: in function '_build_target' [C:\Program Files (x86)\xmake\actions\build\build.lua:167]: in function '_build_target_and_deps' [C:\Program Files (x86)\xmake\actions\build\build.lua:239]: in function 'build' [C:\Program Files (x86)\xmake\actions\build\main.lua:59]: [C]: in function 'xpcall' [C:\Program Files (x86)\xmake\core\sandbox\modules\try.lua:100]: in function 'try' [C:\Program Files (x86)\xmake\actions\build\main.lua:57]: [C]: in function 'load' [C:\Program Files (x86)\xmake/core/base/task.lua:503]: in function 'run' [C:\Program Files (x86)\xmake/core/main.lua:242]:

Commands:

set QT_SHARED=C:\Qt\Qt5.12.2\5.12.2
set NDK_ROOT_PATH=%USERPROFILE%\AppData\Local\Android\Sdk\ndk-bundle
echo Configuring build...
xmake f -p android  --qt=%QT_SHARED% --qt_sdkver=5 --ndk=%NDK_ROOT_PATH% --ndk_sdkver=24 -k shared -c

-- add modes: debug and release 
add_rules("mode.debug", "mode.release")

-- add target target("qt_Android")

-- add rules
add_rules("qt.application")
set_kind("shared")

-- add headers
add_headerfiles("src/*.h")
add_includedirs("C:/Qt/Qt5.12.2/5.12.2/android_armv7/include") --fix error QtGui/qtguiglobal.h

-- add files
add_files("src/*.cpp")
add_files("src/qml.qrc")

-- add frameworks
add_frameworks("QtQuick")
**Output:**

checking for the architecture ... armv7-a checking for the NDK directory ... C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle checking for the SDK version of NDK ... 24 checking for the toolchains version of NDK ... 4.9 checking for the Qt SDK directory ... C:\Qt\Qt5.12.2\5.12.2\android_armv7 checking for the Qt SDK version ... 5

preparing build: configure { ld = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ ndk = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle plat = android buildir = build ndk_toolchains_ver = 4.9 ndk_sdkver = 24 arch = armv7-a mode = release gcc_toolchain = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64 clean = true qt_sdkver = 5 host = windows cross = arm-linux-androideabi- sh = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ kind = shared bin = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin ccache = true qt = C:\Qt\Qt5.12.2\5.12.2 }

waruqi commented 5 years ago

Qt/android doesn't support it yet, I haven't tested it yet. I will support it in the next version.

If you are interested, you can help support it and submit a pr.

waruqi commented 5 years ago
add_includedirs("C:/Qt/Qt5.12.2/5.12.2/android_armv7/include") --fix error QtGui/qtguiglobal.h

I have fixed this problem in dev branch. I have tested it and build passed for qt/android on macOS. But on windows, I have not tested it yet.

waruqi commented 5 years ago

xmake f -p android --qt=%QT_SHARED% --qt_sdkver=5 --ndk=%NDK_ROOT_PATH% --ndk_sdkver=24 -k shared -c

We need not set -k shared

add_rules("qt.application")
set_kind("shared")

rules("qt.application") is application program, not shared library. We cannot set set_kind("shared")

kassane commented 5 years ago

Ok, I removed it.

We need not set -k shared

add_rules("qt.application")
set_kind("shared")

rules("qt.application") is application program, not shared library. We cannot set set_kind("shared")

I was able to build the project, but still need to attach to AndroidDeployQt. I'm testing the as qtcreator 4.10 beta, in which it allows me to compile in cmake for android. One of the steps after the build is to generate android_deployment_settings.json file and then use deploy.

androiddeployqt.exe --input %BUILD_DIR%/android_deployment_settings.json --output %BUILD_DIR%/android-build --android-platform %ANDROID_NDK_PLATFORM% --jdk "C:/Program Files/Java/jdk1.8.0_211" --gradle --gdbserver
waruqi commented 5 years ago

Ok, I removed it.

We need not set -k shared

add_rules("qt.application")
set_kind("shared")

rules("qt.application") is application program, not shared library. We cannot set set_kind("shared")

I was able to build the project

After you updated the dev branch version, has it been built successfully?

kassane commented 5 years ago

I use the dev version and compiled normally generating a linux binary. But it would be nice if it were a library to attach to androiddeployqt

waruqi commented 5 years ago

Ok, I removed it.

We need not set -k shared

add_rules("qt.application")
set_kind("shared")

rules("qt.application") is application program, not shared library. We cannot set set_kind("shared")

I was able to build the project, but still need to attach to AndroidDeployQt. I'm testing the as qtcreator 4.10 beta, in which it allows me to compile in cmake for android. One of the steps after the build is to generate android_deployment_settings.json file and then use deploy.

androiddeployqt.exe --input %BUILD_DIR%/android_deployment_settings.json --output %BUILD_DIR%/android-build --android-platform %ANDROID_NDK_PLATFORM% --jdk "C:/Program Files/Java/jdk1.8.0_211" --gradle --gdbserver

You can write a custom script(on_install) in xmake.lua to deploy target.

target("test")
    ...

    on_install(function (target)
          io.writefile("$(buildir)/android_deployment_settings.json", "xxxxxx")
          os.exec("androiddeployqt.exe --input $(buildir)/android_deployment_settings.json --output $(buildir)/android-build --android-platform $(ndk) --jdk \"C:/Program Files/Java/jdk1.8.0_211\" --gradle --gdbserver")
    end)

Then you can run xmake install to deploy it after building.

kassane commented 5 years ago

Output:[install]

error: installation failed, may permission denied!

waruqi commented 5 years ago

Please add -v -D to get more error info.

xmake install -v -D

kassane commented 5 years ago

Diagnostic:

configure { ndk = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle plat = android buildir = build ndk_toolchains_ver = 4.9 ndk_sdkver = 24 arch = armv7-a clean = true host = windows gcc_toolchain = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64 mode = release qt_sdkver = 5 cxx = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ cross = arm-linux-androideabi- bin = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin kind = static ccache = true sh = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ ld = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ qt = C:\msys64\clang64 } C:\Program Files (x86)\xmake/core/base/os.lua:700: exec(C:\msys64\clang64/bin/androiddeployqt.exe --input build/android_deployment_settings.json --output build/android-build --android-platform 24 --jdk C:/Program Files/Java/jdk1.8.0_211/ --gradle --gdbserver) failed(-1)! stack traceback: [C]: in function 'error' [C:\Program Files (x86)\xmake/core/base/os.lua:700]: in function 'raise' [C:\Program Files (x86)\xmake\core\sandbox\modules\os.lua:383]: in function 'exec' [...s\Catarino\Documents\Programming\Cpp\QtAndroid\xmake.lua:24]: in function 'script' [C:\Program Files (x86)\xmake\actions\install\install.lua:205]: in function '_install_target' [C:\Program Files (x86)\xmake\actions\install\install.lua:232]: in function '_install_target_and_deps' [C:\Program Files (x86)\xmake\actions\install\install.lua:252]: in function 'install' [C:\Program Files (x86)\xmake\actions\install\main.lua:82]:

kassane commented 5 years ago

When I use the command prompt itself the same execution code returns this:

Application binary is not in output directory: C:/Users/kassane/Documents/Programming/Cpp/QtAndroid/build/android-build//libs/armeabi-v7a/ProjectName. Please run 'mingw32-make install INSTALL_ROOT=C:/Users/kassane/Documents/Programming/Cpp/QtAndroid/build/android-build/' first.

waruqi commented 5 years ago
os.exec("C:\\msys64\\clang64\\bin\\androiddeployqt.exe --input build\\android_deployment_settings.json --output build\\android-build --android-platform 24 --jdk \"C:\\Program Files\\Java\\jdk1.8.0_211\" --gradle --gdbserver")
waruqi commented 5 years ago

Or

os.exec("C:\\msys64\\clang64\\bin\\androiddeployqt.exe", {"--input", "build\\android_deployment_settings.json", "--output", "build\\android-build", "--android-platform", "24", "--jdk", "C:\\Program Files\\Java\\jdk1.8.0_211", "--gradle", "--gdbserver"})
waruqi commented 5 years ago

I just provide an example code to tell you that you can customize the install script to implement a custom deployment. How to implement it requires you to do it yourself.

Don't copy the example code I provided directly.

kassane commented 5 years ago

Same error:

error: installation failed, may permission denied!

waruqi commented 5 years ago
io.writefile("$(buildir)/android_deployment_settings.json", [[{
    "application-binary": "%s/ProjectName", 
    "description": "This file is generated by androiddeployqt and should not be modified by hand.", 
    "ndk": "%s", 
    "ndk-host": "windows-x86_64", 
    "qml-root-path": "", 
    "qt": "%s", 
    "sdk": "C:/Users/kassane/AppData/Local/Android/Sdk", 
    "sdkBuildToolsRevision": "28.0.3", 
    "stdcpp-path": "%s/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so", 
    "target-architecture": "armeabi-v7a", 
    "tool-prefix": "llvm", 
    "toolchain-prefix": "llvm", 
    "useLLVM": true
}]], get_config("buildir"), get_config("ndk"), get_config("qt"), get_config("ndk"))
waruqi commented 5 years ago

Or you can use add_configfiles() to add a template file android_deployment_settings.json.in, you can see https://github.com/xmake-io/xmake/issues/320

target("xxx")
    add_configfiles("android_deployment_settings.json.in")
    set_configvar("ndk", get_config("ndk"))
    set_configvar("qt", get_config("qt"))
    set_configvar("buildir", get_config("buildir"))

android_deployment_settings.json.in

{
    "application-binary": "${buildir}/ProjectName", 
    "description": "This file is generated by androiddeployqt and should not be modified by hand.", 
    "ndk": "$(ndk)", 
    "ndk-host": "windows-x86_64", 
    "qml-root-path": "", 
    "qt": "${qt}", 
    "sdk": "C:/Users/kassane/AppData/Local/Android/Sdk", 
    "sdkBuildToolsRevision": "28.0.3", 
    "stdcpp-path": "${ndk}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so", 
    "target-architecture": "armeabi-v7a", 
    "tool-prefix": "llvm", 
    "toolchain-prefix": "llvm", 
    "useLLVM": true
}
kassane commented 5 years ago

Project test: https://github.com/kassane/qt-android-example-xmake

kassane commented 5 years ago

For the 3rdparty part always occurs an error at least in windows. I will try in linux to know if something changes.

waruqi commented 5 years ago

Project test: https://github.com/kassane/qt-android-example-xmake

I improved the xmake.lua and android_deployment_settings.json.in files, but you still need to handle some vars and pathes with TODO yourself.

Please update xmake dev version first, I fixed some problems.

If you want to know verbose install errors, you can run xmake i -v -D

kassane commented 5 years ago

Output:

checking for the architecture ... armv7-a checking for the NDK directory ... C:\Users\kassane/AppData/Local/Android/Sdk/ndk-bundle checking for the SDK version of NDK ... 24 checking for the toolchains version of NDK ... 4.9 checking for the Qt SDK directory ... C:\msys64\clang64\android_armv7 checking for the Qt SDK version ... 5 generating android\android_deployment_settings.json.in ... cache generating android\AndroidManifest.xml.in ... cache

configure
{
ld = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++
ndk = C:\Users\kassane/AppData/Local/Android/Sdk/ndk-bundle
plat = android
sdk = C:\Users\kassane/AppData/Local/Android/Sdk
buildir = build
ndk_toolchains_ver = 4.9
ndk_sdkver = 24
arch = armv7-a
clean = true
gcc_toolchain = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64
mode = release
qt_sdkver = 5
host = windows
cross = arm-linux-androideabi-
ccache = true
kind = shared
bin = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin
sh = C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++
qt = C:/msys64/clang64
}

C:\Program Files (x86)\xmake/core/base/os.lua:700: execv(C:\msys64\clang64\bin\androiddeployqt --input build\android_deployment_settings.json --output build\android-build --android-platform 24 --gradle --gdbserver) failed(-1)! stack traceback: [C]: in function 'error' [C:\Program Files (x86)\xmake/core/base/os.lua:700]: in function 'raise' [C:\Program Files (x86)\xmake\core\sandbox\modules\os.lua:411]: in function 'execv' [...ments\Programming\Cpp\qt-android-example-xmake\xmake.lua:61]: in function 'script' [C:\Program Files (x86)\xmake\actions\install\install.lua:208]: in function '_install_target' [C:\Program Files (x86)\xmake\actions\install\install.lua:235]: in function '_install_target_and_deps' [C:\Program Files (x86)\xmake\actions\install\install.lua:255]: in function 'install' [C:\Program Files (x86)\xmake\actions\install\main.lua:82]:

error: installation failed, may permission denied! checkinfo: runv(sudo.exe -h) failed(-1)! checking for the sudo ... no

waruqi commented 5 years ago

I modified it on the dev branch, you can try again.

kassane commented 5 years ago

xmake dev updated. I tried to use install mode of xmake but windows does not allow generating the same error mentioned above. However I tried separately with a batch script and it resulted in this: androiddeployqt output

Generating Android Package
  Input file: ./build/android_deployment_settings.json
  Output directory: C:/Users/kassane/Documents/Programming/Cpp/qt-android-example-xmake/build/android-build/
  Application binary: build/android/armv7-a/release/qt-android-example-xmake
  Android build platform: android-27
  Install to device: No
  -- Skipping C:/msys64/clang64/android_armv7/plugins/iconengines/libqsvgicon.so. It has unmet dependencies: lib/libQt5Svg.so,lib/libQt5Widgets.so.
  -- Skipping C:/msys64/clang64/android_armv7/plugins/imageformats/libqsvg.so. It has unmet dependencies: lib/libQt5Svg.so,lib/libQt5Widgets.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt/labs/calendar/libqtlabscalendarplugin.so. It has unmet dependencies: lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt/labs/location/liblocationlabsplugin.so. It has unmet dependencies: lib/libQt5Concurrent.so,lib/libQt5Location.so,lib/libQt5Positioning.so,lib/libQt5PositioningQuick.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt/labs/platform/libqtlabsplatformplugin.so. It has unmet dependencies: lib/libQt5Widgets.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Animation/libquick3danimationplugin.so. It has unmet dependencies: lib/libQt53DAnimation.so,lib/libQt53DCore.so,lib/libQt53DQuick.so,lib/libQt53DQuickAnimation.so,lib/libQt53DQuickRender.so,lib/libQt53DRender.so,lib/libQt5Concurrent.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Core/libquick3dcoreplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DQuick.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Extras/libquick3dextrasplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DExtras.so,lib/libQt53DInput.so,lib/libQt53DLogic.so,lib/libQt53DQuick.so,lib/libQt53DQuickExtras.so,lib/libQt53DRender.so,lib/libQt5Concurrent.so,lib/libQt5Gamepad.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Input/libquick3dinputplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DInput.so,lib/libQt53DQuick.so,lib/libQt53DQuickInput.so,lib/libQt5Gamepad.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Logic/libquick3dlogicplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DLogic.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/Qt3D/Render/libquick3drenderplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DQuick.so,lib/libQt53DQuickRender.so,lib/libQt53DRender.so,lib/libQt5Concurrent.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtBluetooth/libdeclarative_bluetooth.so. It has unmet dependencies: lib/libQt5Bluetooth.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtGamepad/libdeclarative_gamepad.so. It has unmet dependencies: lib/libQt5Gamepad.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtLocation/libdeclarative_location.so. It has unmet dependencies: lib/libQt5Concurrent.so,lib/libQt5Location.so,lib/libQt5Positioning.so,lib/libQt5PositioningQuick.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtMultimedia/libdeclarative_multimedia.so. It has unmet dependencies: lib/libQt5Multimedia.so,lib/libQt5MultimediaQuick.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtNfc/libdeclarative_nfc.so. It has unmet dependencies: lib/libQt5Nfc.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtPositioning/libdeclarative_positioning.so. It has unmet dependencies: lib/libQt5Positioning.so,lib/libQt5PositioningQuick.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQml/RemoteObjects/libqtqmlremoteobjects.so. It has unmet dependencies: lib/libQt5RemoteObjects.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Controls.2/Fusion/libqtquickcontrols2fusionstyleplugin.so. It has unmet dependencies: lib/libQt5QuickControls2.so,lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Controls.2/Imagine/libqtquickcontrols2imaginestyleplugin.so. It has unmet dependencies: lib/libQt5QuickControls2.so,lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so. It has unmet dependencies: lib/libQt5QuickControls2.so,lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Controls.2/Material/libqtquickcontrols2materialstyleplugin.so. It has unmet dependencies: lib/libQt5QuickControls2.so,lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Controls.2/Universal/libqtquickcontrols2universalstyleplugin.so. It has unmet dependencies: lib/libQt5QuickControls2.so,lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/LocalStorage/libqmllocalstorageplugin.so. It has unmet dependencies: lib/libQt5Sql.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/PrivateWidgets/libwidgetsplugin.so. It has unmet dependencies: lib/libQt5Widgets.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Scene2D/libqtquickscene2dplugin.so. It has unmet dependencies: lib/libQt53DCore.so,lib/libQt53DInput.so,lib/libQt53DLogic.so,lib/libQt53DQuick.so,lib/libQt53DQuickScene2D.so,lib/libQt53DRender.so,lib/libQt5Concurrent.so,lib/libQt5Gamepad.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Scene3D/libqtquickscene3dplugin.so. It has unmet dependencies: lib/libQt53DAnimation.so,lib/libQt53DCore.so,lib/libQt53DInput.so,lib/libQt53DLogic.so,lib/libQt53DRender.so,lib/libQt5Concurrent.so,lib/libQt5Gamepad.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Shapes/libqmlshapesplugin.so. It has unmet dependencies: lib/libQt5QuickShapes.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/Templates.2/libqtquicktemplates2plugin.so. It has unmet dependencies: lib/libQt5QuickTemplates2.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtQuick/XmlListModel/libqmlxmllistmodelplugin.so. It has unmet dependencies: lib/libQt5XmlPatterns.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtRemoteObjects/libqtremoteobjects.so. It has unmet dependencies: lib/libQt5RemoteObjects.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtScxml/libdeclarative_scxml.so. It has unmet dependencies: lib/libQt5Scxml.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtSensors/libdeclarative_sensors.so. It has unmet dependencies: lib/libQt5Sensors.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtTest/libqmltestplugin.so. It has unmet dependencies: lib/libQt5QuickTest.so,lib/libQt5Test.so,lib/libQt5Widgets.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtWebChannel/libdeclarative_webchannel.so. It has unmet dependencies: lib/libQt5WebChannel.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtWebSockets/libdeclarative_qmlwebsockets.so. It has unmet dependencies: lib/libQt5WebSockets.so.
  -- Skipping C:/msys64/clang64/android_armv7/qml/QtWebView/libdeclarative_webview.so. It has unmet dependencies: lib/libQt5WebView.so.

Application binary is not in output directory: C:/Users/kassane/Documents/Programming/Cpp/qt-android-example-xmake/build/android-build//libs/armeabi-v7a/qt-android-example-xmake.
Please run 'mingw32-make install INSTALL_ROOT=C:/Users/kassane/Documents/Programming/Cpp/qt-android-example-xmake/build/android-build/' first.
waruqi commented 5 years ago

You can first study how to use androiddeployqt, and I will support the built-in deployment qt program to android in the next version.

waruqi commented 5 years ago

I have supported androiddeployqt for qt.application rules. We don't need to make any changes in xmake.lua to deploy apk.

Please update dev branch of xmake to try it again.

For example:

$ xmake create -t quickapp_qt -l c++ appdemo
$ cd appdemo
$ xmake f -p android --ndk=~/Downloads/android-ndk-r19c/ --android_sdk=~/Library/Android/sdk/ -c 
$ xmake
[  0%]: compiling.qt.qrc src/qml.qrc
[ 50%]: ccache compiling.release src/main.cpp
[100%]: linking.release libappdemo.so
[100%]: generating.qt.app appdemo.apk

It will compile and generate an apk file, then we can install this apk:

$ xmake install
installing appdemo ...
installing build/android/armv7-a/release/appdemo.apk ..
Success
install ok!👌

The xmake.lua file

add_rules("mode.debug", "mode.release")

target("appdemo")
    add_rules("qt.application")
    add_headerfiles("src/*.h")

    add_files("src/*.cpp") 
    add_files("src/qml.qrc")

    add_frameworks("QtQuick")

Note: I have only tested it on macos at present, and have not tested it on windows. And we need high version ndk, e.g. android-ndk-r19c

I have improved your example project and tested it on macOS. https://github.com/kassane/qt-android-example-xmake/tree/android_deploy WechatIMG235

kassane commented 5 years ago

I tested on Linux is works!

status: ArchLinux: OK Windows: Error

Windows 10:

checking for the architecture ... armv7-a checking for the NDK directory ... C:\Users\kassane\AppData\Local\Android\Sdk\ndk-bundle checking for the SDK version of NDK ... 24 checking for the toolchains version of NDK ... 4.9 checking for the Android SDK directory ... C:\Users\kassane\AppData\Local\Android\Sdk checking for the Build Tools Version of Android SDK ... 28.0.3 checking for the Qt SDK directory ... C:\msys64\clang64\android_armv7 checking for the Qt SDK version ... 5.12.3

[100%]: generating.qt.app qt-android-example-xmake.apk
C:\msys64\clang64\android_armv7\bin\androiddeployqt.exe --input build\.qt\app\android\qt-android-example-xmake\android-deployment-settings.json --output build\.qt\app\android\qt-android-example-xmake\android-build --android-platform android-24 --jdk C:/Progra~1/Java/jdk1.8.0_211/ --gradle --no-gdbserver
Warning: Android platform 'android-28' does not exist in SDK.
eleaselibqt-android-example-xmake.so.ndroidarmv7-a
error: C:\Program Files (x86)\xmake/core/base/os.lua:715: C:\Program Files (x86)\xmake/core/base/os.lua:715: execv(C:\msys64\clang64\android_armv7\bin\androiddeployqt.exe --input build\.qt\app\android\qt-android-example-xmake\android-deployment-settings.json --output build\.qt\app\android\qt-android-example-xmake\android-build --android-platform android-24 --jdk C:/Progra~1/Java/jdk1.8.0_211/ --gradle --no-gdbserver) failed(2)!
stack traceback:
[C]: in function 'error'
[C:\Program Files (x86)\xmake/core/base/os.lua:715]: in function 'raise'
[C:\Program Files (x86)\xmake\core\sandbox\modules\os.lua:414]:
[C:\Program Files (x86)\xmake\core\sandbox\modules\os.lua:334]: in function 'vrunv'
[C:\Program Files (x86)\xmake\rules\qt\xmake.lua:201]: in function 'after_build'
[C:\Program Files (x86)\xmake\actions\build\build.lua:125]: in function 'script'
[C:\Program Files (x86)\xmake\actions\build\build.lua:140]: in function '_build_target'
[C:\Program Files (x86)\xmake\actions\build\build.lua:167]: in function '_build_target_and_deps'
[C:\Program Files (x86)\xmake\actions\build\build.lua:239]: in function 'build'
[C:\Program Files (x86)\xmake\actions\build\main.lua:59]:

I have installed the platforms in android_sdk: 24 & 28

waruqi commented 5 years ago

I don't have a windows environment right now, you can try to improve the following code.

https://github.com/xmake-io/xmake/blob/75a596217a9fec0e8706803d71456eba47e2f48c/xmake/rules/qt/xmake.lua#L96