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 and NDK](#31-extract-android-sdk-and-ndk)**
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 3.4. **[macOS specific prerequisites](#34-macos-specific-prerequisites)**
16 4. **[Get the source code](#4-get-the-source-code)**
17 5. **[Build tools and dependencies](#5-build-tools-and-dependencies)**
18 5.1. **[Advanced Configure Options](#51-advanced-configure-options)**
19 6. **[Build binary add-ons](#6-build-binary-add-ons)**
20 7. **[Build Kodi](#7-build-kodi)**
21 8. **[Package](#8-package)**
22 9. **[Install](#9-install)**
23 10. **[Debugging Kodi](#10-debugging-kodi)**
25 ## 1. Document conventions
26 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.
28 This is a comment that provides context:
31 this is another command
35 **Example:** Clone Kodi's current master branch:
37 git clone https://github.com/xbmc/xbmc kodi
40 Commands that contain strings enclosed in angle brackets denote something you need to change to suit your needs.
42 git clone -b <branch-name> https://github.com/xbmc/xbmc kodi
45 **Example:** Clone Kodi's current Krypton branch:
47 git clone -b Krypton https://github.com/xbmc/xbmc kodi
50 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 **NOTE:** Linux is user friendly... It's just very particular about who its friends are.
53 **TIP:** Algorithm is what developers call code they do not want to explain.
54 **WARNING:** Developers don't change light bulbs. It's a hardware problem.
56 **[back to top](#table-of-contents)** | **[back to section top](#1-document-conventions)**
58 ## 2. Install the required packages
59 Install build dependencies needed to cross-compile Kodi for Android:
61 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
63 **NOTE:** If you're running a 32bit Debian/Ubuntu distribution, remove `lib32stdc++6 lib32z1 lib32z1-dev` from the command.
64 **NOTE:** Gradle 7.0.2+ requires Jave Runtime 11+. Check java version by running `java --version`. If version is < 11, set JAVA_HOME to java 11+ home directory._
67 **[back to top](#table-of-contents)**
70 Building Kodi for Android requires Android NDK revision 20b. For the SDK just use the latest available.
71 Kodi CI/CD platforms currently use r21e for build testing and releases, so we recommend using r21e for the most tested build experience
73 * **[Android SDK](https://developer.android.com/studio/index.html)** (Look for `Get just the command line tools`)
74 * **[Android NDK](https://developer.android.com/ndk/downloads/index.html)**
76 ### 3.1. Extract Android SDK and NDK
77 Create needed directories:
79 mkdir -p $HOME/android-tools/android-sdk-linux
82 Extract Android SDK Command line tools:
84 unzip $HOME/Downloads/commandlinetools-linux-6200805_latest.zip -d $HOME/android-tools/android-sdk-linux/
87 **NOTE:** Since we're using the latest SDK Command line tools available, filename can change over time. Adapt the `unzip` command accordingly.
91 unzip $HOME/Downloads/android-ndk-r21e-linux-x86_64.zip -d $HOME/android-tools
94 ### 3.2. Configure Android SDK
95 Before Android SDK can be used, you need to accept the licenses and configure it:
97 cd $HOME/android-tools/android-sdk-linux/cmdline-tools/bin
98 ./sdkmanager --sdk_root=$(pwd)/../.. --licenses
99 ./sdkmanager --sdk_root=$(pwd)/../.. platform-tools
100 ./sdkmanager --sdk_root=$(pwd)/../.. "platforms;android-33"
101 ./sdkmanager --sdk_root=$(pwd)/../.. "build-tools;30.0.3"
104 ### 3.3. Create a key to sign debug APKs
105 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.
108 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
111 ### 3.4. macOS specific prerequisites
112 * **[Java Development Kit 11+ (JDK)](http://www.oracle.com/technetwork/java/javase/downloads/index.html)** installed.
113 * Normal macOS installations filesystem is case insensitive but compiling for Android requires a case sensitive filesystem. Generate a writeable hdd image and format it with hfs+ (case sensitive) issuing
114 * `hdiutil create -type UDIF -fs 'Case-sensitive Journaled HFS+' -size 20g -volname android-dev $HOME/android-dev.dmg`
115 * Whenever you want to compile/develop you need to mount the image
116 * `open ~/android-dev.dmg`
117 * Once you have your hdd image with case sensitive hfs+ file system execute all the steps inside of this filesystem. You need to adapt all paths in this guide so that they match your local environment. As an example here is a configure line that demonstrates possible paths:
118 * `./configure --with-tarballs=/Users/Shared/xbmc-depends/tarballs --host=arm-linux-androideabi --with-sdk-path=/Volumes/android-dev/android/android-sdk-macosx --with-ndk-path=/Volumes/android-dev/android/android-ndk-r21e --prefix=/Volumes/android-dev/android/xbmc-depends`
120 **[back to top](#table-of-contents)** | **[back to section top](#3-prerequisites)**
122 ## 4. Get the source code
123 Change to your `home` directory:
128 Clone Kodi's current master branch:
130 git clone https://github.com/xbmc/xbmc kodi
133 ## 5. Build tools and dependencies
134 Prepare to configure build:
136 cd $HOME/kodi/tools/depends
140 **TIP:** Look for comments starting with `Or ...` and only execute the command(s) you need.
142 Configure build for aarch64:
144 ./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-ndk-r21e --prefix=$HOME/android-tools/xbmc-depends
147 Or configure build for arm:
149 ./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-ndk-r21e --prefix=$HOME/android-tools/xbmc-depends
152 Or configure build for x86:
154 ./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-ndk-r21e --prefix=$HOME/android-tools/xbmc-depends
157 Or configure build for x86_64:
159 ./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-ndk-r21e --prefix=$HOME/android-tools/xbmc-depends
162 > **Note:** Android x86 and x86_64 are not maintained and are not 100% sure that everything works correctly!
164 Build tools and dependencies:
166 make -j$(getconf _NPROCESSORS_ONLN)
169 **TIP:** 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`).
171 **WARNING:** 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.
173 ### 5.1. Advanced Configure Options
179 --with-toolchain=<path>
181 specify path to toolchain. Auto set for android. Defaults to xcode root for darwin, /usr for linux
184 --enable-debug=<yes:no>
186 enable debugging information (default is yes)
194 --with-tarballs=<path>
196 path where tarballs will be saved [prefix/xbmc-tarballs]
201 optional. specify target cpu. guessed if not specified
204 --with-linker=<linker>
206 specify linker to use. (default is ld)
209 --with-platform=<platform>
214 --enable-gplv3=<yes:no>
216 enable gplv3 components. (default is yes)
219 --with-target-cflags=<cflags>
221 C compiler flags (target)
224 --with-target-cxxflags=<cxxflags>
226 C++ compiler flags (target)
229 --with-target-ldflags=<ldflags>
231 linker flags. Use e.g. for -l<lib> (target)
234 --with-ffmpeg-options
236 FFmpeg configure options, e.g. --enable-vaapi (target)
239 **Android Specific:**
242 --with-ndk-api=<ndk number>
244 specify ndk level (optional for android), default is 21.]
247 --with-ndk-path=<path>
249 specify path to ndk (required for android only)
252 --with-sdk-path=<path>
254 specify path to sdk (required for android only)
257 **[back to top](#table-of-contents)** | **[back to section top](#5-build-tools-and-dependencies)**
259 ## 6. Build binary add-ons
260 You can find a complete list of available binary add-ons **[here](https://github.com/xbmc/repo-binary-addons)**.
262 Change to Kodi's source code directory:
269 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons
272 Build specific add-ons:
274 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons ADDONS="audioencoder.flac pvr.vdr.vnsi audiodecoder.snesapu"
277 Build a specific group of add-ons:
279 make -j$(getconf _NPROCESSORS_ONLN) -C tools/depends/target/binary-addons ADDONS="pvr.*"
282 Clean-up binary add-ons:
284 make -C tools/depends/target/binary-addons clean
287 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)
289 **[back to top](#table-of-contents)**
292 Configure CMake build:
295 make -C tools/depends/target/cmakebuildsys
298 **TIP:** 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.
300 mkdir $HOME/kodi-build
301 make -C tools/depends/target/cmakebuildsys BUILD_DIR=$HOME/kodi-build
307 make -j$(getconf _NPROCESSORS_ONLN)
310 **[back to top](#table-of-contents)**
313 CMake generates a target called `apk` which will package Kodi ready for distribution.
320 Generated `apk` file will be inside `$HOME/kodi`.
322 **[back to top](#table-of-contents)**
325 Connect your Android device to your computer through USB and enable the `Unknown sources` option in your device settings.
327 Make sure `adb` is installed:
334 cd $HOME/kodi-android
336 adb -s <device-id> install -r <generated-apk-name-here>.apk
339 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.
341 **[back to top](#table-of-contents)**
343 ## 10. Debugging Kodi
344 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).
346 Access the log output of your Android device:
348 adb -s <device-id> logcat
351 Install a new build over the existing one:
353 adb -e install -r images/xbmcapp-debug.apk
356 Launch Kodi on Android Emulator without the GUI:
358 adb shell am start -a android.intent.action.MAIN -n org.xbmc.xbmc/android.app.NativeActivity
361 Kill a misbehaving Kodi:
363 adb shell ps | grep org.xbmc | awk '{print $2}' | xargs adb shell kill
366 Filter logcat messages by a specific tag (e.g. `Kodi`):
371 Enable CheckJNI (**before** starting the Kodi):
373 adb shell setprop debug.checkjni 1
376 **NOTE:** 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)**