Build for Android
Are you familiar with Android development environment and interested to learn more while helping the project?
How to build the Android app:
You will need
A computer with Linux installed
The development of the Android app has to be done on Linux, it’s currently not possible to build the native parts on Windows
The Android platform tools including a compatible NDK
Builds have been tested with Android NDK 23.0.7599858, other NDK versions may or may not work
An Android or ChromeOS device or simulator
The Android app can run in a simulator, however some bugs may be present in a simulator that are not present on a mobile device or vice-versa. If you are able to, we strongly suggest you build and run for a physical device.
You should connect this device or simulator to your computer using adb
Build Collabora Office Core for Android
Clone the monorepo
Collabora Online and the LibreOffice core now live in a single Gerrit monorepo - core is the engine/ subdirectory of the online repo, so there is no separate core clone any more. Code review happens on Gerrit, not GitHub pull requests; see the first contribution guide for the full workflow.
Collabora Online is hosted on Gerrit as a single monorepo. The LibreOffice core sits under engine/ inside the same repo, so there is no separate core clone any more.
For an anonymous read-only clone (no account needed):
git clone https://gerrit.collaboraoffice.com/online collabora-online
If you have a Gerrit account and plan to push changes for review, clone over SSH instead:
git clone ssh://YOUR_USERNAME@gerrit.collaboraoffice.com:29418/online collabora-online
See the first contribution guide for the full Gerrit workflow (SSH key, commit-msg hook, pushing to refs/for/main).
Switch to the local clone’s directory:
cd collabora-online
Move into core
Core lives under engine/ inside the monorepo - that is where you do the core build:
Collabora Office core lives inside the online monorepo under engine/, so a separate core clone is no longer needed. If you have not cloned the monorepo yet, run the clone-online step above first. Then move into the core tree:
cd engine
git checkout main
If you already have the monorepo cloned for another job, you may use git worktrees to speed up this step.
Configure Collabora Office core
Decide what architecture you are going to build for. This will depend on your android device’s ABI. We support building for armeabi-v7a, arm64-v8a, x86 and x86_64.
If you’re not sure what your phone’s architecture is, you can either research online or use adb to get a list of valid architectures
$ adb shell getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi
Create a file called autogen.input in your core clone with the
following content:
--build=x86_64-unknown-linux-gnu
--with-android-ndk=/home/$USER/Android/Sdk/ndk/23.0.7599858
--with-android-sdk=/home/$USER/Android/Sdk
--enable-sal-log
--enable-dbgutil
You also need to add a line specifying which architecture you’re building for
For arm64-v8a
--with-distro=CPAndroidAarch64
For armeabi-v7a
--with-distro=CPAndroid
For x86_64
--with-distro=CPAndroidX86_64
For x86
--with-distro=CPAndroidX86
For example, if you have a device that supports arm64-v8a your autogen.input
should contain this content
--build=x86_64-unknown-linux-gnu
--with-android-ndk=/home/$USER/Android/Sdk/ndk-bundle
--with-android-sdk=/home/$USER/Android/Sdk
--enable-sal-log
--with-distro=CPAndroidAarch64
--enable-dbgutil
Finally, run
./autogen.sh
Build Collabora Office core
Run make and wait a while for the build to finish…
make
Build Collabora Online
You need a copy of POCO and libzstd built for Android in order to build the Android app. You can use these scripts to build those
- POCO - use build-poco-android.sh
- libzstd - use build-zstd-android.sh
Configuring the build
Let’s set some variables based on what we just built…
export ABI=arm64-v8a
export POCO_DIR=/opt/android-poco
export ZSTD_DIR=/opt/android-zstd
export CO_BUILDDIR=/opt/libreoffice
…remember to change your ABI to the ABI you’re building the app for, POCO_DIR and ZSTD_DIR to the output directories of the build scripts, and CO_BUILDDIR to the engine/ subdirectory of the monorepo where you built Collabora Office core.
Now step back to the top of the monorepo (one level up from engine/) and configure the Collabora Online build
cd ..
./autogen.sh
./configure --enable-androidapp \
--with-lo-builddir=${CO_BUILDDIR} \
--with-poco-includes=${POCO_DIR}/install/include \
--with-poco-libs=${POCO_DIR}/install/${ABI}/lib \
--with-zstd-includes=${ZSTD_DIR}/lib \
--with-zstd-libs=${ZSTD_DIR}/install/${ABI}/lib \
--enable-silent-rules \
--enable-debug \
--with-android-abi=${ABI}
Build Collabora Online
Once again, after configuring the build you can run it with make
make
Build the android app
Option 1: Using Android studio
This is the recommended way to build the Android app
- Open Android studio
- Open the
androidsubdirectory as a project - Use
build -> make projectto run the build
Option 2: Using gradle from the command line
It may be harder to debug the app without using Android Studio. Unless you have prior experience with debugging Android apps outside Android Studio (or otherwise aren’t able to use Android Studio) we recommend you follow Option 1
cd android
./gradlew build
Debugging
To debug the native Collabora Office core code in Android Studio, you need the debugging symbols and to setup Android Studio to actually read & use them.
Add android/obj/local/armeabi-v7a from core.git as a Symbol Directory
In Android Studio, choose Run -> Debug… -> Edit Configurations…
There go to the Android App -> app, choose the Debugger tab, and:
Debug type: Auto (or Dual)
Symbol Directories: here add the full path, like…
/local/libreoffice/master-android/android/obj/local/${ABI}
…making sure to substitute ${ABI} for the ABI you builts for
This path contains the non-stripped version of the liblo-native-code.so, and the debugger will read the symbols from that one (even if the APK contains the stripped version). NB ensure that this is before any internal source directories - since the internal source contains stripped native code.
Alternatively you can add the following to your ~/.lldbinit instead:
settings set target.inline-breakpoint-strategy always
settings append target.exec-search-paths /local/libreoffice/master-android/android/obj/local/${ABI}
To use pretty printers for types like OUString, add the following to your ~/.lldbinit:
command script import '/local/libreoffice/master-android/solenv/lldb/libreoffice/LO.py'
From now on, you will be able to debug directly in the Android Studio debugger. Happy debugging!
Cross-compiling with icecream to speed up your build
If you use icecream for parallel building, you can use it for cross-compilation too.
# first generate a tarball with the toolchain (once)
icecc-create-env ~/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang ~/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++
And add it and the paths to the compiler as the first things to the autogen.input:
CC=icecc [here copy what the output of ./autogen.sh without icecream said for C compiler]
CXX=icecc [here copy what the output of ./autogen.sh without icecream said for C++ compiler]
ICECC_VERSION=/path/to/the/tarball/generated/above/955ceb546ceb7a5715bf0223ddd788fe.tar.gz
--with-parallelism=[amount of cpu threads in your icecream farm]
--enable-icecream
[...the original autogen.input...]
So the result will look something like this:
CC=icecc /home/$USER/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon -Wl,--fix-cortex-a8 -gcc-toolchain /home/$USER/Android/Sdk/ndk-bundle/to>
CXX=icecc /home/$USER/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon -Wl,--fix-cortex-a8 -gcc-toolchain /home/$USER/Android/Sdk/ndk-bundle>
ICECC_VERSION=/local/libreoffice/android/955ceb546ceb7a5715bf0223ddd788fe.tar.gz
--with-parallelism=25
--enable-icecream
--build=x86_64-unknown-linux-gnu
--with-android-ndk=/home/$USER/Android/Sdk/ndk-bundle
--with-android-sdk=/home/$USER/Android/Sdk
--with-distro=CPAndroid
--enable-sal-log
Edit page

