Qt client on Android

Do you want to help out with Freeciv development? Then check out this forum.
louis94
Hardened
Posts: 221
Joined: Thu Apr 25, 2013 10:17 pm
Location: Belgium

Qt client on Android

Postby louis94 » Mon Aug 19, 2019 5:45 pm

This topic is about getting the Qt client ready for Android. There is already a port of the SDL client.

Android is officially supported by Qt through their qmake tool and QtAndroidExtras module. The application is compiled as a dynamic library that is loaded by a Java wrapper.

I managed to compile the Qt client and connect to a remote game from an Android device. Currently, text input and basic interaction are working, including scrolling the map. You better not use a smartphone though. Here's a mandatory screenshot:
Screenshot_20190819_145828.png

My modified version of freeciv can be found at https://github.com/lmoureaux/freeciv/co ... ndroid-2.6. Most changes are related to the way tilesets are loaded (apk don't work like traditional Linux packages) and the build system (to build the client as a shared object).

Here's my configure command (for an x86 target):

Code: Select all

export ANDROID_NDK_ROOT=/path/to/android/sdk
export ANDROID_NDK_ROOT=/path/to/android/ndk
export "CPP=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/i868-linux-android21-clang -E"
export CC=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android21-clang
export CXX=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android21-clang++
export LD=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-ld
export MOCCMD=/path/to/qt/bin/moc

export MOCCMD=/path/to/qt/bin/moc
./configure --enable-client=qt \
            --disable-fcmp \
            --disable-ruledit \
            --host=x86-linux-android \
            --build=x86_64-linux-gnu \
            --disable-server \
            --disable-nls \
            --with-qt5-root=/path/to/qt \
            --with-qt5-includes=/path/to/qt/include \
            --with-qt5-libs=/path/to/qt/lib \
            --prefix=/ \
            --with-sysroot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot/ \
            --disable-sdl-mixer \
            --enable-shared \
            --disable-static \
            --with-android-sdk $ANDROID_SDK_ROOT \
            --with-android-ndk $ANDROID_NDK_ROOT

Important notes about this configure command:
  • The --with-qt5-root argument can be used only when cross-compiling for Android. Do not add a trailing / or the app will not work
  • The build host must start with x86, x86_64, armeabi-v7a or arm64-v8a
  • ARM builds haven't been tested
You need to build Qt from source. Download a tarball from the website and follow the instructions. You need only QtBase and QtAndroidExtras. Use of a recent Qt release is recommended (I use 5.13.1).

The APK can be built using a custom target:

Code: Select all

make apk

[edit 2019-08-20] Added some required env vars
[edit 2019-09-19] Updated configure command for cross-compilation; scrolling the map works; added Qt instructions
[edit 2019-09-28] Updated configure command for newly added Android-specific files; first mention of make apk
Last edited by louis94 on Sat Sep 28, 2019 1:58 am, edited 1 time in total.

louis94
Hardened
Posts: 221
Joined: Thu Apr 25, 2013 10:17 pm
Location: Belgium

Re: Qt client on Android

Postby louis94 » Fri Sep 13, 2019 9:45 am

The repo has been updated with touch support for scrolling the map. This means the game can be played.

louis94
Hardened
Posts: 221
Joined: Thu Apr 25, 2013 10:17 pm
Location: Belgium

Re: Qt client on Android

Postby louis94 » Sat Sep 28, 2019 2:00 am

I just pushed an update that makes it much easier to create an APK. Most parameters can just be passed to configure (some paths are still hardcoded for Debian-based distros, eg the JVM).