1 ![Kodi Logo](resources/banner_slim.png)
4 This guide has been tested with Ubuntu 16.04 (Xenial) x86_64. It is meant to cross-compile Kodi for Android using **[Kodi's unified depends build system](../tools/depends/README.md)**. Please read it in full before you proceed to familiarize yourself with the build procedure.
6 It should work if you're using macOS. If that is the case, read **[macOS specific prerequisites](#34-macos-specific-prerequisites)** first.
9 1. **[Document conventions](#1-document-conventions)**
10 2. **[Install the required packages](#2-install-the-required-packages)**
11 3. **[Prerequisites](#3-prerequisites)**
12 3.1. **[Extract Android SDK](#31-extract-android-sdk)**
13 3.2. **[Configure Android SDK](#32-configure-android-sdk)**
14 3.3. **[Create a key to sign debug APKs](#33-create-a-key-to-sign-debug-apks)**
15 4. **[Get the source code](#4-get-the-source-code)**
16 5. **[Build tools and dependencies](#5-build-tools-and-dependencies)**
17 5.1. **[Advanced Configure Options](#51-advanced-configure-options)**
18 6. **[Build binary add-ons](#6-build-binary-add-ons)**
19 7. **[Build Kodi](#7-build-kodi)**
20 8. **[Package](#8-package)**
21 9. **[Install](#9-install)**
22 10. **[Debugging Kodi](#10-debugging-kodi)**
24 ## 1. Document conventions
25 This guide assumes you are using `terminal`, also known as `console`, `command-line` or simply `cli`. Commands need to be run at the terminal, one at a time and in the provided order.
27 This is a comment that provides context:
30 this is another command
34 **Example:** Clone Kodi's current master branch:
36 git clone https://github.com/xbmc/xbmc kodi
39 Commands that contain strings enclosed in angle brackets denote something you need to change to suit your needs.
41 git clone -b <branch-name> https://github.com/xbmc/xbmc kodi
44 **Example:** Clone Kodi's current Krypton branch:
46 git clone -b Krypton https://github.com/xbmc/xbmc kodi
49 Several different strategies are used to draw your attention to certain pieces of information. In order of how critical the information is, these items are marked as a note, tip, or warning. For example:
52 > Linux is user friendly... It's just very particular about who its friends are.
55 > Algorithm is what developers call code they do not want to explain.
58 > Developers don't change light bulbs. It's a hardware problem.
60 **[back to top](#table-of-contents)** | **[back to section top](#1-document-conventions)**
62 ## 2. Install the required packages
63 Install build dependencies needed to cross-compile Kodi for Android:
65 sudo apt install autoconf bison build-essential curl default-jdk flex gawk git gperf lib32stdc++6 lib32z1 lib32z1-dev libcurl4-openssl-dev unzip zip zlib1g-dev
68 > If you're running a 32bit Debian/Ubuntu distribution, remove `lib32stdc++6 lib32z1 lib32z1-dev` from the command.
71 > Gradle 8.0+ requires JDK 17+. Check java version by running `java --version`. If version is < 17, set `JAVA_HOME` environment variable to java 17+ home directory.
73 **[back to top](#table-of-contents)**
76 Building Kodi for Android requires Android NDK revision 27c. For the SDK just use the latest available.
77 Kodi CI/CD platforms currently use r27c for build testing and releases, so we recommend using r27c for the most tested build experience
79 * **[Android SDK](https://developer.android.com/studio/index.html)** (Look for `Get just the command line tools`)
81 ### 3.1. Extract Android SDK
82 Create needed directories:
84 mkdir -p $HOME/android-tools/android-sdk-linux
87 Extract Android SDK Command line tools:
89 unzip $HOME/Downloads/commandlinetools-linux-6200805_latest.zip -d $HOME/android-tools/android-sdk-linux/
93 > Since we're using the latest SDK Command line tools available, filename can change over time. Adapt the `unzip` command accordingly.
95 ### 3.2. Configure Android SDK
96 Before Android SDK can be used, you need to accept the licenses and configure it:
98 cd $HOME/android-tools/android-sdk-linux/cmdline-tools/bin
99 ./sdkmanager --sdk_root=$(pwd)/../.. --licenses
100 ./sdkmanager --sdk_root=$(pwd)/../.. platform-tools
101 ./sdkmanager --sdk_root=$(pwd)/../.. "platforms;android-35"
102 ./sdkmanager --sdk_root=$(pwd)/../.. "build-tools;34.0.0"
103 ./sdkmanager --sdk_root=$(pwd)/../.. "ndk;27.2.12479018"
106 ### 3.3. Create a key to sign debug APKs
107 All packages must be signed. The following command will generate a self-signed debug key. If the result is a cryptic error, it probably just means a debug key already existed.
110 keytool -genkey -keystore ~/.android/debug.keystore -v -alias androiddebugkey -dname "CN=Android Debug,O=Android,C=US" -keypass android -storepass android -keyalg RSA -keysize 2048 -validity 10000
113 **[back to top](#table-of-contents)** | **[back to section top](#3-prerequisites)**
115 ## 4. Get the source code
116 Change to your `home` directory:
121 Clone Kodi's current master branch:
123 git clone https://github.com/xbmc/xbmc kodi
126 ## 5. Build tools and dependencies
127 Prepare to configure build:
129 cd $HOME/kodi/tools/depends
134 > Look for comments starting with `Or ...` and only execute the command(s) you need.
136 Configure build for aarch64:
138 ./configure --with-tarballs=$HOME/android-tools/xbmc-tarballs --host=aarch64-linux-android --with-sdk-path=$HOME/android-tools/android-sdk-linux --with-ndk-path=$HOME/android-tools/android-sdk-linux/ndk/27.2.12479018 --prefix=$HOME/android-tools/xbmc-depends
141 Or configure build for arm:
143 ./configure --with-tarballs=$HOME/android-tools/xbmc-tarballs --host=arm-linux-androideabi --with-sdk-path=$HOME/android-tools/android-sdk-linux --with-ndk-path=$HOME/android-tools/android-sdk-linux/ndk/27.2.12479018 --prefix=$HOME/android-tools/xbmc-depends
146 Or configure build for x86:
148 ./configure --with-tarballs=$HOME/android-tools/xbmc-tarballs --host=i686-linux-android --with-sdk-path=$HOME/android-tools/android-sdk-linux --with-ndk-path=$HOME/android-tools/android-sdk-linux/ndk/27.2.12479018 --prefix=$HOME/android-tools/xbmc-depends
151 Or configure build for x86_64:
153 ./configure --with-tarballs=$HOME/android-tools/xbmc-tarballs --host=x86_64-linux-android --with-sdk-path=$HOME/android-tools/android-sdk-linux --with-ndk-path=$HOME/android-tools/android-sdk-linux/ndk/27.2.12479018 --prefix=$HOME/android-tools/xbmc-depends
157 > Android x86 and x86_64 are not maintained and are not 100% sure that everything works correctly!
159 Build tools and dependencies:
161 make -j$(getconf _NPROCESSORS_ONLN)
165 > By adding `-j<number>` to the make command, you can choose how many concurrent jobs will be used and expedite the build process. It is recommended to use `-j$(getconf _NPROCESSORS_ONLN)` to compile on all available processor cores. The build machine can also be configured to do this automatically by adding `export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"` to your shell config (e.g. `~/.bashrc`).
168 > Look for the `Dependencies built successfully.` success message. If in doubt run a single threaded `make` command until the message appears. If the single make fails, clean the specific library by issuing `make -C target/<name_of_failed_lib> distclean` and run `make`again.
170 ### 5.1. Advanced Configure Options
176 --with-toolchain=<path>
178 specify path to toolchain. Auto set for android. Defaults to xcode root for darwin, /usr for linux
181 --enable-debug=<yes:no>
183 enable debugging information (default is yes)
191 --with-tarballs=<path>
193 path where tarballs will be saved [prefix/xbmc-tarballs]
198 optional. specify target cpu. guessed if not specified
201 --with-linker=<linker>
203 specify linker to use. (default is ld)
206 --with-platform=<platform>
211 --enable-gplv3=<yes:no>
213 enable gplv3 components. (default is yes)
216 --with-target-cflags=<cflags>
218 C compiler flags (target)
221 --with-target-cxxflags=<cxxflags>
223 C++ compiler flags (target)
226 --with-target-ldflags=<ldflags>
228 linker flags. Use e.g. for -l<lib> (target)
231 --with-ffmpeg-options
233 FFmpeg configure options, e.g. --enable-vaapi (target)
236 **Android Specific:**
239 --with-ndk-api=<ndk number>
241 specify ndk level (optional for android), default is 24.]
244 --with-ndk-path=<path>
246 specify path to ndk (required for android only)
249 --with-sdk-path=<path>
251 specify path to sdk (required for android only)
254 **[back to top](#table-of-contents)** | **[back to section top](#5-build-tools-and-dependencies)**
256 ## 6. Build binary add-ons
257 You can find a complete list of available binary add-ons **[here](https://github.com/xbmc/repo-binary-addons)**.
259 Change to Kodi's source code directory:
266 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons
269 Build specific add-ons:
271 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons ADDONS="audioencoder.flac pvr.vdr.vnsi audiodecoder.snesapu"
274 Build a specific group of add-ons:
276 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons ADDONS="pvr.*"
279 Clean-up binary add-ons:
281 make -C tools/depends/target/binary-addons clean
284 For additional information on regular expression usage for ADDONS_TO_BUILD, view ADDONS_TO_BUILD section located at [Kodi add-ons CMake based buildsystem](../cmake/addons/README.md)
286 **[back to top](#table-of-contents)**
289 Configure CMake build:
292 make -C tools/depends/target/cmakebuildsys
296 > BUILD_DIR can be provided as an argument to cmakebuildsys. This allows you to provide an alternate build location. Change all paths onwards as required if BUILD_DIR option used.
299 mkdir $HOME/kodi-build
300 make -C tools/depends/target/cmakebuildsys BUILD_DIR=$HOME/kodi-build
306 make -j$(getconf _NPROCESSORS_ONLN)
309 **[back to top](#table-of-contents)**
312 CMake generates a target called `apk` which will package Kodi ready for distribution.
319 Generated `apk` file will be inside `$HOME/kodi`.
321 **[back to top](#table-of-contents)**
324 Connect your Android device to your computer through USB and enable the `Unknown sources` option in your device settings.
326 Make sure `adb` is installed:
333 cd $HOME/kodi-android
335 adb -s <device-id> install -r <generated-apk-name-here>.apk
338 The *device-id* can be retrieved from the list returned by the `adb devices` command and is the first value in the row representing your device.
340 **[back to top](#table-of-contents)**
342 ## 10. Debugging Kodi
343 To be able to see what is happening while running Kodi you need to enable `USB debugging` in your device settings (already enabled in the Android Emulator).
345 Access the log output of your Android device:
347 adb -s <device-id> logcat
350 Install a new build over the existing one:
352 adb -e install -r images/xbmcapp-debug.apk
355 Launch Kodi on Android Emulator without the GUI:
357 adb shell am start -a android.intent.action.MAIN -n org.xbmc.xbmc/android.app.NativeActivity
360 Kill a misbehaving Kodi:
362 adb shell ps | grep org.xbmc | awk '{print $2}' | xargs adb shell kill
365 Filter logcat messages by a specific tag (e.g. `Kodi`):
370 Enable CheckJNI (**before** starting the Kodi):
372 adb shell setprop debug.checkjni 1
376 > These commands assume that current directory is `$HOME/kodi-build/tools/android/packaging` and that the proper SDK/NDK paths are set.
378 GDB can be used to debug, though the support is rather primitive. Rather than using `gdb` directly, you will need to use `ndk-gdb` which wraps it. You can use the `-p/--project` switches or instead you will need to `cd` to `$HOME/kodi-build/tools/android/packaging/xbmc` and execute it from there.
383 This will open the installed version of Kodi and break. The warnings can be ignored as we have the appropriate paths already setup.
385 **[back to top](#table-of-contents)** | **[back to section top](#10-debugging-kodi)**