Skip to content

Commit d99718d

Browse files
committed
Update and improve presets to build for Android under Windows
* Allow building libsyncthing with system SQLite3 * Allow using Qt libraries from my Arch Linux repo instead of using the official Qt installer
1 parent de15073 commit d99718d

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

CMakePresets.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@
593593
}
594594
},
595595
{
596-
"name": "win-android",
596+
"name": "win-android-base",
597597
"inherits": ["no-webview", "no-kde", "qt6", "builtin-translations"],
598598
"displayName": "Target *-linux-android using MSYS2 and Arch Linux's Android packaging (invoke e.g. \"source android-env aarch64\" before invoking CMake)",
599599
"description": "Build targeting Android, paths and flags are specific to MSYS2 and Arch Linux's Android packaging, invoke e.g. \"source android-env aarch64\" for required environment variables",
@@ -616,7 +616,7 @@
616616
"CMAKE_CXX_FLAGS_RELEASE": {"type": "STRING", "value": "$env{ANDROID_CXXFLAGS}"},
617617
"CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES": {"type": "PATH", "value": "$env{ANDROID_PREFIX_INCLUDE}"},
618618
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": {"type": "STRING", "value": "$env{ANDROID_LDFLAGS}"},
619-
"CMAKE_FIND_ROOT_PATH": {"type": "PATH", "value": "$env{QT_PLATFORMS_ROOT}/android_$env{QT_ANDROID_ARCH};$env{ANDROID_PREFIX}"},
619+
"CMAKE_FIND_ROOT_PATH": {"type": "PATH", "value": "$env{ANDROID_PREFIX}"},
620620
"CMAKE_PREFIX_PATH": {"type": "PATH", "value": "$env{ANDROID_PREFIX}"},
621621
"CMAKE_INSTALL_PREFIX": {"type": "PATH", "value": "$env{ANDROID_PREFIX}"},
622622
"CMAKE_INSTALL_LIBDIR": {"type": "PATH", "value": "lib"},
@@ -626,7 +626,28 @@
626626
"LIB_INSTALL_DIR": {"type": "PATH", "value": "$env{ANDROID_PREFIX_LIB}"},
627627
"SYSCONF_INSTALL_DIR": {"type": "PATH", "value": "$env{ANDROID_PREFIX_ETC}"},
628628
"SHARE_INSTALL_DIR": {"type": "PATH", "value": "$env{ANDROID_PREFIX_SHARE}"},
629-
"PKG_CONFIG_EXECUTABLE": {"type": "FILEPATH", "value": "$env{MSYS2_ROOT}/usr/bin/$env{ANDROID_PKGCONFIG}"}
629+
"PKG_CONFIG_EXECUTABLE": {"type": "FILEPATH", "value": "$env{MSYS2_ROOT}/usr/bin/$env{ANDROID_PKGCONFIG}"},
630+
"CGO_CFLAGS_APPEND": {"type": "STRING", "value": "-I$env{ANDROID_PREFIX_INCLUDE}"},
631+
"CGO_LDFLAGS_APPEND": {"type": "STRING", "value": "-L$env{ANDROID_PREFIX_LIB}"}
632+
}
633+
},
634+
{
635+
"name": "win-android",
636+
"inherits": ["win-android-base"],
637+
"displayName": "Target *-linux-android using MSYS2 and Arch Linux's Android packaging (invoke e.g. \"source android-env aarch64\" before invoking CMake)",
638+
"description": "Build targeting Android, paths and flags are specific to MSYS2 and Arch Linux's Android packaging, invoke e.g. \"source android-env aarch64\" for required environment variables",
639+
"cacheVariables": {
640+
"QT_HOST_PATH": {"type": "PATH", "value": "$env{MSYS2_ROOT}/ucrt64"}
641+
}
642+
},
643+
{
644+
"name": "win-android-official-qt",
645+
"inherits": ["win-android-base"],
646+
"displayName": "Target *-linux-android using official Qt builds and additionally MSYS2 and Arch Linux's Android packaging (invoke e.g. \"source android-env aarch64\" before invoking CMake)",
647+
"description": "Build targeting Android, paths and flags are specific to MSYS2 and Arch Linux's Android packaging, invoke e.g. \"source android-env aarch64\" for required environment variables",
648+
"binaryDir": "$env{BUILD_DIR}/${sourceDirName}/win-android-official-qt-$env{ANDROID_ABI}",
649+
"cacheVariables": {
650+
"CMAKE_FIND_ROOT_PATH": {"type": "PATH", "value": "$env{QT_PLATFORMS_ROOT}/android_$env{QT_ANDROID_ARCH};$env{ANDROID_PREFIX}"}
630651
}
631652
}
632653
],
@@ -670,7 +691,8 @@
670691
{"name": "win-x64-msvc-static", "configurePreset": "win-x64-msvc-static"},
671692
{"name": "win-x64-msvc-static-devel", "configurePreset": "win-x64-msvc-static-devel"},
672693
{"name": "win-x64-msvc-static-debug", "configurePreset": "win-x64-msvc-static-debug"},
673-
{"name": "win-android", "configurePreset": "win-android"}
694+
{"name": "win-android", "configurePreset": "win-android"},
695+
{"name": "win-android-official-qt", "configurePreset": "win-android-official-qt"}
674696
],
675697
"testPresets": [
676698
{

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,18 @@ The NDK needs to be [downloaded separately](https://developer.android.com/ndk/do
517517
<summary>Install Qt</summary>
518518

519519
The easiest way to install Qt is via the official [Qt installer](https://www.qt.io/download-qt-installer-oss).
520-
The open source version is sufficient but a Qt account is required.
520+
The open source version is sufficient but a Qt account is required. Alternatively, you can also skip the this
521+
step and install Qt like the other additional libraries as mentioned in the next section.
521522
</details>
522523

523524
<details>
524525
<summary>Install additional native libraries for Android</summary>
525526

526527
Additional libraries can be installed via MSYS2 using my Arch Linux packaging. Note that this is not generally
527-
required to build Syncthing Tray as use of libiconv, Boost, OpenSSL and CppUnit is optional (so only Qt is
528-
required besides the C/C++ standard libraries). However, the following instructions and the CMake preset make
529-
use of MSYS2 and the `android-cmake` package. The OpenSSL package is also very likely wanted for TLS support.
528+
required to build Syncthing Tray as use of libiconv, Boost, OpenSSL, CppUnit and system SQLite3 is optional (so
529+
only Qt is required besides the C/C++ standard libraries). However, the following instructions and the CMake
530+
preset make use of MSYS2 and the `android-cmake` package. The OpenSSL package is also very likely wanted for TLS
531+
support.
530532

531533
To install additional libraries via MSYS2, add my Arch Linux repository to
532534
`/etc/pacman.conf`:
@@ -542,7 +544,7 @@ After following [instructions for importing my GPG key](https://martchus.dyn.f3l
542544
can install Android packages, e.g.:
543545

544546
```
545-
pacman -Syu android-cmake android-{x86-64,aarch64}-{boost,libiconv,openssl,cppunit} \
547+
pacman -Syu android-cmake android-{x86-64,aarch64}-{boost,libiconv,openssl,cppunit,sqlite} \
546548
--assume-installed android-ndk --assume-installed android-sdk
547549
````
548550
@@ -551,19 +553,26 @@ You may even install a few KDE libraries like Kirigami:
551553
pacman -S android-{aarch64,x86-64}-kirigami --assume-installed=android-{aarch64,x86-64}-qt6-{base,declarative,shadertools,svg,5compat}
552554
```
553555
554-
Whether this will actually work at runtime hasn't been tested yet. One definitely has to make sure that the
555-
used version of Qt is at least as new as the version the KDE libraries from my repo have been linked against.
556+
You may also install Qt itself from my repo instead of relying on official Qt builds:
557+
```
558+
pacman -S --assume-installed={ant,java-runtime-headless-openjdk=17} --assume-installed=android-{ndk,sdk,sdk-build-tools,sdk-platform-tools,platform-35} android-x86-64-qt6-declarative android-x86-64-qt6-tools android-x86-64-qt6-svg android-x86-64-qt6-translations
559+
```
560+
561+
Note that when using Qt for Android from my repo you also need to install a matching version of Qt for
562+
Windows from MSYS2 mingw-w64 repos for host tooling.
563+
564+
When just using KDE libraries from my repo but Qt from the official installer you need to make sure that
565+
the installed version of Qt is at least as new as the version the KDE libraries from my repo have been
566+
linked against.
556567
557568
The libraries will end up under `/opt/android-libs` within your MSYS2 installation. Do not install any non
558569
`android-*-` packages, though. They will have file conflicts with packages provided by MSYS2 and are not usable
559570
under Windows anyway.
560571
561-
The Qt packages for Android cannot be used as well because they rely on the Qt packaging provided by Arch Linux
562-
for tooling. (Maybe the Qt packages provided by MSYS2 mingw-w64 packages could be used for tooling. This hasn't
563-
been tested yet, though.)
564-
565572
To search for available Android packages on my repo per architecture one can use e.g.
566573
`pacman -Ss android-aarch64-`.
574+
575+
Whether builds using any of these libraries will actually work at runtime hasn't been tested yet.
567576
</details>
568577
569578
<details>
@@ -573,9 +582,11 @@ Set the following environment variables:
573582
574583
* `ANDROID_HOME`: path to the Android SDK
575584
* `ANDROID_NDK_HOME`: path to the Android NDK
585+
* `ANDROID_TOOLCHAIN`: path to the Android toolchain (part of the Android NDK)
586+
* `ANDROID_MINIMUM_PLATFORM=24`: set minimum platform to Android 7.0 in-line with packages from my Arch repo
576587
* `ANDROID_STUDIO_HOME`: Android studio install directory (for adding Java to `PATH` and setting `JAVA_HOME`)
577588
* `QT_PLATFORMS_ROOT`: directory containing Qt platform directories installed via the official Qt installer,
578-
e.g. `D:/programming/qt/6.8.0`
589+
e.g. `D:/programming/qt/6.10.0` (not required when installing Qt for Android via my Arch repo)
579590
* `QT_ANDROID_ARCH`: `x86_64`/`arm64_v8a`/`armv7`/`x86`
580591
* `QT_ANDROID_KEYSTORE_PATH`: path of directory containing Android keystores
581592
* `QT_ANDROID_KEYSTORE_ALIAS`: name of Android keystore to use
@@ -587,8 +598,9 @@ Then the build can be conducted in a MSYS2 shell, e.g.:
587598
588599
```
589600
source android-env x86-64 # or aarch64
590-
cmake --preset win-android
591-
cmake --build --preset win-android
601+
cmake --preset win-android # to use everything from MSYS2
602+
cmake --preset win-android-official-qt # to use Qt from QT_PLATFORMS_ROOT
603+
cmake --build --preset win-android # or win-android-official-qt
592604
```
593605
</details>
594606

0 commit comments

Comments
 (0)