Skip to content

Make it easier to build for Android from source (build libsodium as external project)

Make it easier to build for Android from source

This MR is the outcome of challenges I ran into while trying to set up a local workflow for building Keysmith from source (local clone) for Android.

Bundle libsodium via CMake external project

The biggest problem is that the libsodium dependency is not covered 'natively' by the KDE Android SDK tooling. This means that there is not a single command that can be run to build Keysmith, you always have to enter an interactive session in the SDK container and type out commands manually.

To fix this, I registered libsodium as an external project for CMake within Keysmith. This behaviour is optional and gated on two variables:

  • BUILD_EXTERNAL which is a boolean flag that can be set to opt-in to this behaviour.
  • ANDROID, if set the external project will be opted into automatically. The assumption here is that when building Keysmith for Android, the KDE Android SDK is always used and therefore opting in is desirable.

Most of the effort here goes into making this work for the Android SDK. As a side effect, the same feature can be used to build libsodium also with the 'native' toolchain on a Unix-like host. The feature does not work on e.g. Windows however since some shell scripting is used.

Move Android manifest around

Another issue is that the KDE Android SDK will overwrite the versionCode attribute in the AndroidManifest.xml file with an auto-generated value. When building against a local clone, this results in changes to the local work tree that must never be committed and must be manually reset.

To work around this problem, I renamed the source Android manifest to AndroidManifest.xml.in and use CMake to copy it in place for the KDE Android SDK scripts to pick it up. The AndroidManifest.xml file itself can now be safely gitignore'd, helping to ensure it won't be comitted.

This change depends on: sysadmin/ci-tooling!65 (merged) In order to test it, you may need to docker pull kdeorg/android-sdk to update your KDE Android SDK first.

Edited by Johan Ouwerkerk

Merge request reports