Android/Environment via Container: Difference between revisions

From KDE Community Wiki
No edit summary
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
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):
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">
<syntaxhighlight lang="bash">
docker run -ti --rm kdeorg/android-arm-sdk bash
docker run -ti --rm kdeorg/android-sdk bash
</syntaxhighlight>
</syntaxhighlight>


Line 14: Line 14:
To make it easy to compile applications we put some scripts to get started. They can be triggered like this:
To make it easy to compile applications we put some scripts to get started. They can be triggered like this:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
docker run -ti --rm kdeorg/android-arm-sdk /opt/helpers/build-generic <appname>
docker run -ti --rm kdeorg/android-sdk /opt/helpers/build-generic <appname>
</syntaxhighlight>
</syntaxhighlight>


The following command will compile okular with all its dependencies and output an apk to our /tmp directory.
== 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 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
docker run -ti --rm -v /tmp:/output kdeorg/android-arm-sdk /opt/helpers/build-generic okular
docker run -ti --rm -v $HOME/apks:/output kdeorg/android-sdk /opt/helpers/build-generic okular
</syntaxhighlight>
</syntaxhighlight>
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 achived via bind mounts)


== Tricks ==
You can pass multiple -v arguments. For example:
* build-generic fetch the dependencies of <appname>, build them and then build <appname>, outputting an apk to /output. Therefore a volume to /output will catch the result. e.g. <code>-v $HOME/apks:/output</code>
* 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 we want to develop a project locally we can also use volumes and put them in the home directory. e.g. <code>-v $HOME/kde/src:/home/user/src -v $HOME/kde/androidbuild:/home/user/build</code>.
* 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>.
* Note we are passing kdeorg/android-arm-sdk, this is to produce 32-bit arm images, there's also kdeorg/android-aarch64-sdk available as well.

Revision as of 13:18, 9 September 2020

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 an 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 achived 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.