Android/Environment via Container: Difference between revisions

From KDE Community Wiki
(Moved from general Android page)
 
(url does not exist)
 
(20 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= Use Docker Container for KDE on Android Development =
{{Warning|2=Important|The tools mentioned on this page as well as the <code>kdeorg/android-sdk</code>image are deprecated and no longer supported. <br>Instead you should use Craft to build apps for Android as described [https://develop.kde.org/docs/packaging/android here].}}
 
= Using Docker for KDE on Android Development =
This is the easiest way to start cross-compiling and developing Qt applications for Android. The explained Docker image will install all dependencies and setup all environment variables automatically. By this, it closely follows the steps explained in the detailed system setup guide:
This is the easiest way to start cross-compiling and developing Qt applications for Android. The explained Docker image will install all dependencies and setup all environment variables automatically. By this, it closely follows the steps explained in the detailed system setup guide:
* [[Android/Environment|Setup Cross-Building Environment for KDE on Android]]
* [[Android/Environment|Setup Cross-Building Environment for KDE on Android]]


== Use Docker Container ==
== Setting up ==
First, you must install Docker on your system, which should be available via your distribution. Then you only have to checkout the Docker image configuration in <code>git clone git://anongit.kde.org/android-builder.git</code>.
This image alone contains a working Android SDK, NDK and Qt binaries. The easiest is to access it like this (it will be downloaded the first time you use it):
<syntaxhighlight lang="bash">
docker run -ti --rm kdeorg/android-sdk bash
</syntaxhighlight>
 
Here one can start developing at ease in an environment welcoming to projects that use cmake, Qt, ECM, etc.
 
== Building a KDE application ==
To make it easy to compile applications we put some scripts to get started. They can be triggered like this:
<syntaxhighlight lang="bash">
docker run -ti --rm kdeorg/android-sdk /opt/helpers/build-generic <appname>
</syntaxhighlight>
 
== Using Volumes ==
Since we are giving --rm to '''docker run''' everything will be lost once we exit the ''bash'' shell from the '''Setting up''' section or when the ''build-generic'' command from the '''Building an application''' ends.
 
This is particularly bad for the '''Building an application''' case since it will compile your application, create the .apk and then immediately it will get lost :)
 
To solve that we can use volumes. Volumes are a way for docker to punch out of themselves into your local filesystem.


Then in folder <code>image</code> perform the following commands to build, then create, and finally to run your KDE on Android build image:
For example if we want to save the output of the ''build-generic'' command (that ends up in /output inside the docker container) we can do 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
cd image
docker run -ti --rm -v $HOME/apks:/output kdeorg/android-sdk /opt/helpers/build-generic okular
docker build -t kde-android-sdk .
docker create -ti --name myproject kde-android-sdk bash
docker start -i myproject
</syntaxhighlight>
</syntaxhighlight>
More details can be found in the README.md file in the checked out repository.
the extra <code>-v $HOME/apks:/output</code> means: whatever would be written to /output inside the docker container write it to $HOME/apks in my actual filesystem (if you're curious this is achieved via bind mounts)
 
You can pass multiple -v arguments. For example:
* if you already have the source code downloaded in your local filesystem you can pass <code>-v $HOME/path/to/kde/sources:/home/user/src</code> ('''/home/user''' is the docker home path)
* if you want to keep the build artifacts to not have to compile everything all the time you can pass <code>-v $HOME/place/to/store/android/build/artifacts:/home/user/build</code>.
 
== Advanced Usage ==
The enviroment comes with several [https://invent.kde.org/sysadmin/ci-tooling/-/tree/master/system-images/android/sdk helper scripts] to make it easier to build stuff for Android!
 
To run the scripts you need to be in a shell inside the container.
 
=== Build a framework ===
<syntaxhighlight lang="bash">
git clone --depth 1 kde:sysadmin/ci-tooling #only need to be done once
/opt/helpers/build-kde-project ki18n Frameworks
</syntaxhighlight>
Replace '''ki18n''' by the name of the framework you want to build
 
=== Build a custom application ===
If you want to create an APK later you need to get some <code>cmake</code> args first
<syntaxhighlight lang="bash">
python /opt/helpers/get-apk-args.py /home/user/src/yourapp/
</syntaxhighlight>
 
Now we can build the app. Replace <code><ARGS></code> by the output of the previous command. <code>foo</code> technically is supposed to be the git url for your app, but that doesn't matter if it's already checked out.
<syntaxhighlight lang="bash">
/opt/helpers/build-cmake yourapp foo <ARGS>
</syntaxhighlight>
 
There are also scripts for other build systems like <code>/opt/helpers/build-autotools</code>. [https://invent.kde.org/sysadmin/ci-tooling/-/tree/master/system-images/android/sdk Here] you can find all available scripts


==== Change Container Size ====
=== Create an APK ===
By default Docker containers have a size of 10GB. This is sufficient for the typical use case, but usually much too small if you setup a full cross-building toolchain. For this, you have to increase the default container size (note: the following deletes all your current containers, hence do backups and do it with care!)
If you have build your app like described in the previous section you can now create an APK with
* Documentation: https://docs.docker.com/engine/reference/commandline/daemon/
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
service docker stop
/opt/helpers/create-apk yourapp
rm -rf /var/lib/docker
service docker start
docker -d --storage-opt dm.basesize=20G &
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 00:59, 23 September 2023

Important

The tools mentioned on this page as well as the kdeorg/android-sdkimage are deprecated and no longer supported.
Instead you should use Craft to build apps for Android as described here.


Using Docker for KDE on Android Development

This is the easiest way to start cross-compiling and developing Qt applications for Android. The explained Docker image will install all dependencies and setup all environment variables automatically. By this, it closely follows the steps explained in the detailed system setup guide:

Setting up

This image alone contains a working Android SDK, NDK and Qt binaries. The easiest is to access it like this (it will be downloaded the first time you use it):

docker run -ti --rm kdeorg/android-sdk bash

Here one can start developing at ease in an environment welcoming to projects that use cmake, Qt, ECM, etc.

Building a KDE application

To make it easy to compile applications we put some scripts to get started. They can be triggered like this:

docker run -ti --rm kdeorg/android-sdk /opt/helpers/build-generic <appname>

Using Volumes

Since we are giving --rm to docker run everything will be lost once we exit the bash shell from the Setting up section or when the build-generic command from the Building an application ends.

This is particularly bad for the Building an application case since it will compile your application, create the .apk and then immediately it will get lost :)

To solve that we can use volumes. Volumes are a way for docker to punch out of themselves into your local filesystem.

For example if we want to save the output of the build-generic command (that ends up in /output inside the docker container) we can do

docker run -ti --rm -v $HOME/apks:/output kdeorg/android-sdk /opt/helpers/build-generic okular

the extra -v $HOME/apks:/output means: whatever would be written to /output inside the docker container write it to $HOME/apks in my actual filesystem (if you're curious this is achieved via bind mounts)

You can pass multiple -v arguments. For example:

  • if you already have the source code downloaded in your local filesystem you can pass -v $HOME/path/to/kde/sources:/home/user/src (/home/user is the docker home path)
  • if you want to keep the build artifacts to not have to compile everything all the time you can pass -v $HOME/place/to/store/android/build/artifacts:/home/user/build.

Advanced Usage

The enviroment comes with several helper scripts to make it easier to build stuff for Android!

To run the scripts you need to be in a shell inside the container.

Build a framework

git clone --depth 1 kde:sysadmin/ci-tooling #only need to be done once
/opt/helpers/build-kde-project ki18n Frameworks

Replace ki18n by the name of the framework you want to build

Build a custom application

If you want to create an APK later you need to get some cmake args first

python /opt/helpers/get-apk-args.py /home/user/src/yourapp/

Now we can build the app. Replace <ARGS> by the output of the previous command. foo technically is supposed to be the git url for your app, but that doesn't matter if it's already checked out.

/opt/helpers/build-cmake yourapp foo <ARGS>

There are also scripts for other build systems like /opt/helpers/build-autotools. Here you can find all available scripts

Create an APK

If you have build your app like described in the previous section you can now create an APK with

/opt/helpers/create-apk yourapp