Approaching KF5 on Android the road so far

Andreas Cord-Landwehr

September 2, 2016 QtCon, Berlin Introduction About Me & the Talk

About Me IRC-nick: CoLa KDE developer since ≈ 2010 did PhD in algorithmic game theory at Paderborn University % now working as software developer at CLAAS E-Systems

Roadmap of this Talk

1 KDE Frameworks 5 and their purpose on Android

2 high-level structure of a -on-Android app 3 our approach for KF5 on Android: toolchaining in the KDE ecosystem build environment availability CI & quality assurance

4 outlook

2 Approaching KF5 on Android / Andreas Cord-Landwehr Qt/C++ Libraries for Android?! How KDE Frameworks 5 help your C++ app on Android.

KDE Frameworks 5 (KF5) are. . . feature specific drop-in Qt libraries modular with dependencies defined via tiers: tier 1 libraries do not depend on any other KF5 lib easy way to add functionality to a Qt application examples: KArchive, Threadweaver, KItemModels, KItemViews, KI18n . . . available on , Windows, MacOSX, monthly incremental releases LGPL2.1+ licensed build system is CMake based but ship *.pri & *.pro files, too Purpose of KF5 on Android a typical Android app is written in Java use cases for C++ libraries in Android apps: re-use of existing complex C/C++ libraries provide app for different platforms squeeze extra performance out of a device → if any of these reasons applies, you should consider KF5

3 Approaching KF5 on Android / Andreas Cord-Landwehr Anatomy of a Qt-on-Android App A very high-level view.

From a high level view, an Android App. . . is an APK package that contains Android specific parts (e.g. manifest, Java bytecode) can contain native libraries (*.so)

Android Tool Landscape SDK tool suite for building any Android App: libraries, emulator, debugger,. . . NDK tools to introduce C++ code into Android App: GCC & Clang toolchain stripped std C (BIONIC) and other base libs Qt integrates your app via QPA: the integration abstraction QtAndroidExtras: tools for going Android native (JNI) → see BogDan’s talk, Sunday 2:15pm

4 Approaching KF5 on Android / Andreas Cord-Landwehr Our Approach to Provide KF5 for Android The master plan.

1 integrate Qt-on-Android into the KDE tool landscape → provide CMake toolchain

2 make the start easy → provide a full-fledged build environment out of the box

3 ease application porting to Android → provide KF5 Android ports for most used frameworks

4 ensure quality → integrate KF5 unit tests into Android emulator based CI

5 Approaching KF5 on Android / Andreas Cord-Landwehr Cross-Platform Build Tooling How to build an Android app/lib on a Linux host?

Cross-Compiling with CMake CMake is the preferred build system within the KDE community has built-in mechanism called “toolchain files” we ship an Android toolchain via Extra-CMake-Modules (ECM): requires SDK, NDK & Qt paths and sets compiler and linker flags, sets sysroot for libraries like Qt, creates APK packaging build target (including depending libraries) → cmake -DCMAKE_TOOLCHAIN_FILE=AndroidToolchain.cmake details: https://api.kde.org/ecm/toolchain/Android.html

Alternative: QMake and QtCreator Integration QMake has similar functionality there is a nifty integration of Android cross-compiling into QtCreator

6 Approaching KF5 on Android / Andreas Cord-Landwehr Development Setup Your development environment with just 4 commands.

We provide a ready-to-use Docker Container:

1 Setup Android-Builder Container git clone git://anongit..org/android-builder.git → contains: Qt 5.6, SDK, NDK 10e create container: 1 docker build -t kde-android-sdk . 2 docker create -ti –name myproject kde-android-sdk bash 3 docker start -i myproject contains an additional jenkins user that is used for CI

2 CMake Toolchain and APK Packaging environment already configured for user kdeandroid can use kdesrc-build to build all Android-ready KF5: cd /opt/android/ && ./kdesrc-build frameworks-android libraries are installed into a shared install folder → Android toolchain automatically adds them to APK

Detailed instructions: community.kde.org/Android

7 Approaching KF5 on Android / Andreas Cord-Landwehr Android Availability of KDE Framework 5 What builds today? (1/2)

Solving Basic Tasks

Attica KCodecs Open Collaboration Services API handling various text encodings connection to the store.kde.org KCoreAddons KArchive non-gui QtCore convenience addons built-in compression negotiation KImageFormats handling zip, , ar, and 7zip add extra export formats to QImage containers provides QIODevice for gzip, bzip2, ThreadWeaver and xz containers high-level multi-threading KConfig framework persistant platform independent job-based interface to queue tasks app settings and execute them efficiently

Overview: .kde.org/frameworks/index.html

8 Approaching KF5 on Android / Andreas Cord-Landwehr Android Availability of KDE Framework 5 What builds today? (2/2)

Localization KI18n: internationalizing user interface texts based on the GNU translation system features argument capturing, customizable markup & scripting KUnitConversion: convert between different unit systems convert between physical units

Challenging QtWidget Layouts ready-to-use proxymodels & convenience widgets KGuiAddons & KWidgetsAddons: Addons to QtGui and QtWidgets KItemViews: Widget addons for Qt Model/View system KItemModels: Models for Qt Model/View system KCompletion: Text completion helpers and widgets

Overview: api.kde.org/frameworks/index.html

9 Approaching KF5 on Android / Andreas Cord-Landwehr Quality for Android Builds CI & Unit Test Framework

CI Integration of Android Builds ongoing effort in KDE to transition to a Docker based CI Android Docker container was recently integrated in this experimental setup however: current problems with upstream Jenkins-Docker pause progress → hopefully fixed soon → will get then fully automatic CI Unit Testing of Android Builds goal we want to run unit tests within Android emulator task for every unit test we have to: 1 generate a manifest file 2 collect information about files needed for the test 3 generate an APK out of all these files 4 install it at the emulator, run it & download results done have a working proof-of-concept script that does this via Perl script that parses CTest information, generates manifest, packages APK and performs uploading/running/downloading successfully tested with attica still contains functionality that should be in toolchain

10 Approaching KF5 on Android / Andreas Cord-Landwehr Current Challenges & Outlook Still much to do but we are getting somewhere.

Nice to Have Agenda Points Integrate unit testing better into CMake toolchain

Current Major Challenges Completing CI System integration all pieces are there now and now remain to be put together top-priority task to get CI and testing framework running automatically and fixing the issues we find by that :) KNewStuff has high demand but currently cannot provided requires KIO and only provides QtWidget based API not really suited for smartphones ongoing effort to split out a basic framework KIO is building block for many frameworks but relies on DBus there is no DBus available on Android but Binder both use a very different philosophy (RAM vs. CPU)

Contributing: https://phabricator.kde.org/project/view/45/

11 Approaching KF5 on Android / Andreas Cord-Landwehr Thank you for your attention!

Andreas Cord-Landwehr E-mail: [email protected]