Compiling Kodi and building deb packages – Raspbian Stretch
There isn’t much information around the web on how to properly compile and build debian packages out of Kodi. Kodi is an awesome project and its media player capabilities are very much suitable to be used in a Raspberry Pi, I’m not going into much detail about Kodi’s capabilities, if you’re reading this post is because you already know what it is capable of and need to tweak it to your convenience.
I’ve decided to compile a list of things that are needed to be done in order to compile Kodi properly. Feel free to add your comments below if something is not working as expected, I’ll update the guide using your feedback.
This guide assumes that you start with a clean Raspbian Stretch installation, if that’s not your case feel free to skip some the initial steps.
Step 1: Install and Configure Raspbian Stretch
I’m not going to discuss on how you should install Raspbian Stretch on a SD Card, there are several places around the web so I’m assuming that you can google and find that information.
Once you boot your Pi with Raspbian, the first thing you should do is to resize its partition by selecting the “Resize Filesystem” option in raspi-config.
After this is done and you rebooted, configure network access and make sure you have internet access, this is mandatory for this guide to work 🙂
Alternative: You can use a chroot environment, please refer to the instructions on this website.
Step 2: Prepare environment
We will need a bunch of libraries installed in order to compile Kodi. They are not only Kodi’s dependencies, but system tools required to compile, download source code and to help us in our tasks.
First, upgrade Raspbian packages to the latest versions:
sudo apt-get update && sudo apt-get upgrade
Let’s install a few utilities that will be useful to manage source code and to be able to compile and produce binaries:
sudo apt-get install git curl devscripts build-essential
Below are all the dependencies needed to build kodi. I separated them from the above so you can clearly identify what is a kodi dependency and what is not.
sudo apt-get install autoconf automake autotools-dev cmake ccache default-jre \ gawk gdc gperf libasound2-dev libass-dev libavahi-client-dev libavahi-common-dev \ libbluetooth-dev libbluray-dev libboost-dev libboost-thread-dev libbz2-dev \ libcdio-dev libcurl4-openssl-dev libcwiid-dev libdbus-1-dev libenca-dev \ libflac-dev libfontconfig-dev libfreetype6-dev libfribidi-dev libgcrypt-dev \ libgl1-mesa-dev libglew-dev libglu1-mesa-dev libgnutls28-dev libgpg-error-dev \ libiso9660-dev libjasper-dev libjpeg-dev libltdl-dev liblzo2-dev libmad0-dev \ libmicrohttpd-dev libmodplug-dev libmp3lame-dev libmpeg2-4-dev \ default-libmysqlclient-dev libnfs-dev libogg-dev libpcre3-dev libplist-dev \ libpng-dev libpulse-dev librtmp-dev libsamplerate-dev libsdl2-dev \ libsmbclient-dev libsqlite3-dev libssh-dev libtag1-dev libtiff5-dev \ libtinyxml-dev libtool libudev-dev libva-dev libvdpau-dev libvorbis-dev \ libxmu-dev libxrandr-dev libxslt1-dev libxt-dev libyajl-dev nasm python-dev \ python-imaging swig uuid-dev yasm zip zlib1g-dev bluez libspeex-dev \ libspeexdsp-dev libdvdread-dev libdvdnav-dev
If you’re using a chroot environment, please run the following as well:
wget https://raw.githubusercontent.com/Hexxeh/rpi-update/master/rpi-update ./rpi-update
Don’t run rpi-update
unless you know what you’re doing. Check the end of this guide for more information.
Step 3: Compile and install dependencies
There are a few packages that are required by kodi but are not yet available on the raspbian repository, so we will have to compile and install them individually.
At this point in time, these dependencies include: libplatform-dev, libcec4-dev, libbluray-dev and libshairplay-dev. I’ll detail them one by one.
Before doing this step it is advised that you create a directory where all source code will live and will be compiled. I’ll assume that all commands you run from this point forward are done on that place.
Alternative Step 3: An alternative method to this is to install these libraries already compiled and made available at pipplware’s repository. Add this repository to your apt sources as described here and you can run sudo apt-get install libplatform-dev libcec4-dev libbluray-dev libshairplay-dev
.
Note that this repository also contains Kodi already compiled and optimised for your Pi’s architecture (armv6 or armv7) so technically you don’t need to continue further with this guide if what you want is just Kodi running on your raspbian installation. Follow the instructions on the link above and you’re done. The following steps are for those who want to know how to put everything together.
libplatform-dev
This is a pre requisite for building libcec4-dev, so we will need to start with this one. Follow the next steps to generate a deb package and install them.
git clone https://github.com/Pulse-Eight/platform cd platform sed "s/#DIST#/stretch/g" debian/changelog.in > debian/changelog dpkg-buildpackage -us -uc cd .. sudo dpkg -i *.deb
libcec4-dev
This library provides support for HDMI-CEC protocol, it allows the usage of the TV remote to control Kodi. Follow the next steps to generate a deb package and install them.
sudo apt-get install libncurses5-dev git clone https://github.com/Pulse-Eight/libcec.git cd libcec sed "s/#DIST#/stretch/g" debian/changelog.in > debian/changelog sed -i "s/cmake /cmake -DRPI_INCLUDE_DIR=\/opt\/vc\/include -DRPI_LIB_DIR=\/opt\/vc\/lib /" debian/rules dpkg-buildpackage -us -uc cd .. sudo dpkg -i *.deb
libbluray-dev
Kodi needs a version of libbluray which is not available on stock raspbian stretch. So we’ll need to compile it, and we will also patch it with a patch provided by popcornmix to enable certain features needed by Kodi as well.
sudo apt-get install default-jdk javahelper ant doxygen graphviz texlive-latex-base texlive-latex-recommended \ texlive-latex-extra latex-xcolor texlive-fonts-recommended libasm4-java wget http://archive.raspbian.org/raspbian/pool/main/libb/libbluray/libbluray_0.9.3.orig.tar.bz2 tar jxvf libbluray_0.9.3.orig.tar.bz2 rm libbluray_0.9.3.orig.tar.bz2 cd libbluray-0.9.3 wget https://raw.githubusercontent.com/popcornmix/xbmc/krypton_rbp_backports/tools/depends/target/libbluray/bump_to_Nevcairie_v0.9.2.patch patch -p1 < bump_to_Nevcairie_v0.9.2.patch rm bump_to_Nevcairie_v0.9.2.patch tar -zcf ../libbluray_0.9.3.orig.tar.gz . wget http://archive.raspbian.org/raspbian/pool/main/libb/libbluray/libbluray_0.9.3-3.debian.tar.xz tar xf libbluray_0.9.3-3.debian.tar.xz rm libbluray_0.9.3-3.debian.tar.xz dpkg-buildpackage -us -uc cd .. sudo dpkg -i *.deb
libshairplay-dev
Shairplay provides Apple airplay and raop protocol support. This is then required to access such functionalities within Kodi.
First we need to install some dependencies:
sudo apt-get install libavahi-compat-libdnssd-dev libao-dev libao4
Afterwards we perform the following steps to generate the correct tar.gz file that the build system expects.
git clone https://github.com/juhovh/shairplay.git cd shairplay ./autogen.sh tar -zcf ../shairplay_0.9.0+git20151215.d8e9e32d.orig.tar.gz .
This lib also doesn’t provide the debian scripts needed to generate a deb package. So you can get the debian folder which is contained in this file. Once extracted you’ll be able to build the deb package by using the following steps.
dpkg-buildpackage -us -uc cd .. sudo dpkg -i *.deb
Step 4: Compile and Install Kodi (finally)
With all the required dependencies installed, at this time we have what is needed to start with Kodi.
Finally, we are ready, let’s compile Kodi’s github repository (Krypton’s branch), that repository is not fully optimised for Raspberry Pi, but it is enough for the sake of this guide to understand how to compile it.
git clone https://github.com/xbmc/xbmc.git cd xbmc git checkout Krypton
At this point I strongly advise to read Kodi’s documentation on cmake building system. Specially the options section, because this is where you will define what Kodi will support. I’ll include the set I tested with while writing this guide, but be free to experiment with the available options and compile it to your likings.
The first thing to do is to create a build dir, for that purpose I’m going to create a build dir inside kodi’s repository directory:
mkdir build cd build
Once inside let’s call cmake
to configure our build tree. This is where all the options should be set. I’ll be using a set of options that I’ve concluded to be more or less default for a Raspberry Pi, feel free to play around with them.
IMPORTANT: Please note that CPU is not yet defined. You should replace ${CPU}
with the target CPU you’d like to build Kodi’s for. Please use arm1176jzf-s
for Raspberry Pi 0 or 1 and cortex-a7
for Raspberry Pi 2 or 3.
cmake \ -DVERBOSE=1 \ -DCORE_SYSTEM_NAME=rbpi \ -DENABLE_MMAL=ON \ -DENABLE_OPENGL=OFF \ -DWITH_CPU=${CPU} \ -DCMAKE_PREFIX_PATH=/opt/vc \ -DENABLE_OPENGLES=ON \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr \ -DENABLE_AIRTUNES=ON \ -DENABLE_ALSA=ON \ -DENABLE_AVAHI=ON \ -DENABLE_BLURAY=ON \ -DENABLE_CEC=ON \ -DENABLE_DBUS=ON \ -DENABLE_DVDCSS=ON \ -DENABLE_EGL=ON \ -DENABLE_EVENTCLIENTS=ON \ -DENABLE_INTERNAL_FFMPEG=ON \ -DENABLE_INTERNAL_CROSSGUID=ON \ -DENABLE_MICROHTTPD=ON \ -DENABLE_MYSQLCLIENT=ON \ -DENABLE_NFS=ON \ -DENABLE_NONFREE=ON \ -DENABLE_OPENSSL=ON \ -DENABLE_OPTICAL=ON \ -DENABLE_PULSEAUDIO=ON \ -DENABLE_SMBCLIENT=ON \ -DENABLE_SSH=ON \ -DENABLE_UDEV=ON \ -DENABLE_UPNP=ON \ -DENABLE_VAAPI=OFF \ -DENABLE_VDPAU=OFF \ -DENABLE_X11=OFF \ -DENABLE_XSLT=ON \ -DENABLE_LIRC=ON \ -DCPACK_GENERATOR=DEB \ -DDEBIAN_PACKAGE_VERSION=1~ \ -DDEB_PACKAGE_ARCHITECTURE=armhf \ ../project/cmake/
Note on Kodi 18: Replace ../project/cmake/
by ../cmake/
. In Kodi 18, cmake project dir was moved to the repository root, so cmake needs to be adjusted as well.
This creates and generates the needed files to actually compile Kodi. If by any chance you need to repeat this reconfigure step, I’d advise you to delete cmake’s cache and auto generated files so they have to regenerate the build tree and reevaluate all options again. You can do that by doing:
rm -rf CMakeCache.txt CMakeFiles CPackConfig.cmake CTestTestfile.cmake cmake_install.cmake
Once the build tree is done, you can finally compile Kodi. Run the following command and get some refreshments because this is going to take a while 😀
cmake --build . -- VERBOSE=1 -j`nproc`
If everything went ok, SUCCESS!! Kodi is compiled. If not, please post in the comments the errors you got so I can try to provide some guidance.
Now, what is left is to generate the deb packages and have them installed. This is a simple procedure and shouldn’t take more than a couple of seconds. Just run:
cpack
And you’re done ! 😀 Generated debian packages are located in packages
directory. To install them, install its dependencies before, then install the generated packages to have Kodi available in your system, type:
sudo apt-get install python-bluez mesa-utils python-lightblue python-simplejson libaacs0 sudo dpkg -i packages/*.deb
The generated debian packages can be installed on any raspbian, however depending on the CPU you’ve chosen before it may not work properly on all Raspberry PIs, due to the different architectures mentioned above.
Notes on repositories: Regarding Raspberry Pi optimisations, there is a substancial performance increase in playing videos encoded in h264 and h265 (hevc) with one of popcornmix’s branches (newclock5 – Leia – or krypton_rbp_backports) in his own fork of Kodi. For a better experience I strongly recommend that you use popcorn’s krypton_rbp_backports branch. However, this branch depends on an unstable version of the firmware and at the time of the writing of this guide (2017-03-26) it doesn’t compile with cmake unless some changes are made to the source code. So if you’re unexperienced with it, I strongly advice against doing so, proceed at your own risk if you decide to go forward with it.
Alternative method: You can use this script which will do all the work for you, and also generates packages for most of the binary addons, which I’ll cover in another guide.
Step 5: Set systemwide permissions
Thanks to Diogo Santos (Rascas), the maintainer of Pipplware, for figuring out the permissions needed for running Kodi.
Run the following commands for user pi (if you haven’t changed your user name):
sudo usermod -a -G tty pi sudo printf 'SUBSYSTEM=="input", GROUP="input", MODE="0660"\n \ SUBSYSTEM=="tty", KERNEL=="tty[0-9]*", GROUP="tty", MODE="0660"' \ > /etc/udev/rules.d/99-input.rules
To enable systemwide automounts, create or edit the following file:
/etc/polkit-1/localauthority/50-local.d/automount.pkla
with the following content:
[Allow Mount and Automount] Identity=unix-group:plugdev Action=org.freedesktop.udisks* ResultAny=yes ResultInactive=yes ResultActive=yes
If by any reason Reboot and Shutdown options are not available within Kodi, you’ll need to create/edit the file:
cat /etc/polkit-1/localauthority/50-local.d/power.pkla
Which should have the following content:
[Allow consolekit] Identity=unix-group:plugdev Action=org.freedesktop.consolekit* ResultAny=yes ResultInactive=yes ResultActive=yes [Allow login1] Identity=unix-group:plugdev Action=org.freedesktop.login1* ResultAny=yes ResultInactive=yes ResultActive=yes [Allow Upower] Identity=unix-group:plugdev Action=org.freedesktop.upower* ResultAny=yes ResultInactive=yes ResultActive=yes
Step 6: Run Kodi
This is the simplest step, if no errors while installing were detected, kodi
binary should be in your path and you can run it directly.
Please note that binary addons such as PVRs will not be available, those are required to be built separately and it’s covered in this blog post.
That is all for now, I hope you enjoy it and please post in the comments if something didn’t go as expected.
Acknowledgement: I’d like to thank Diogo Santos (Rascas) for all the help and patience during the process of finding it all out. I strongly believe that this guide wouldn’t be available it if weren’t for all his help. Thanks 😀
BTW, the pthread issue I highlighted turned out to be nothing. With -Wnodev that callout was suppressed. The real issue at that time was the string(REPLACE…) syntax issue.
ns….I am build K18 for a second time so i can get a better handle on any issues.
From the first build attempt there was an issue with missing fmt package and with rapidjson package. Once I installed them all was ok and during second build/cmake attempt there were no fmt/rapidjson issues because they had been previously installed.
Two other issues from both build attempts are as follows:
1)
CMake Error at cmake/cpack/CPackConfigDEB.cmake:126 (string):
string sub-command REPLACE requires at least four arguments.
Call Stack (most recent call first):
cmake/scripts/rbpi/Install.cmake:309 (include)
CMakeLists.txt:414 (include)
CODE LOOKED LIKE THIS:
string(REPLACE “\”” “” CHANGELOG ${CHANGELOG})
I CHANGED CODE TO THIS:
string(REPLACE “\”” ” ” CHANGELOG “${CHANGELOG}”)
2)The file generated by cmake for the cpack debian package making process had the following entries which are incorrect. I could not find where the file CPackConfig.cmake was created so I just hacked it to look better:
SET(CPACK_DEBIAN_PACKAGE_VERSION “2:18.0~git20171214.0453-b4e54bf036-di-1~stretch”)
SET(CPACK_DEB_COMPONENT_INSTALL “ON”)
SET(CPACK_GENERATOR “DEB”)
SET(CPACK_INSTALL_CMAKE_PROJECTS “/share/kodi/build;kodi;ALL;/”)
SET(CPACK_INSTALL_PREFIX “/usr”)
SET(CPACK_MODULE_PATH “/share/kodi/cmake/modules”)
SET(CPACK_NSIS_DISPLAY_NAME “kodi 0.0.1”)
SET(CPACK_NSIS_INSTALLER_ICON_CODE “”)
SET(CPACK_NSIS_INSTALLER_MUI_ICON_CODE “”)
SET(CPACK_NSIS_INSTALL_ROOT “$PROGRAMFILES”)
SET(CPACK_NSIS_PACKAGE_NAME “kodi 0.0.1”)
SET(CPACK_OUTPUT_CONFIG_FILE “/share/kodi/build/CPackConfig.cmake”)
SET(CPACK_PACKAGE_DEFAULT_LOCATION “/”)
SET(CPACK_PACKAGE_DESCRIPTION_FILE “/usr/share/cmake-3.7/Templates/CPack.GenericDescription.txt”)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY “kodi built using CMake”)
SET(CPACK_PACKAGE_DIRECTORY “/share/kodi/build/packages”)
SET(CPACK_PACKAGE_FILE_NAME “kodi-0.0.1-armv7l”)
SET(CPACK_PACKAGE_INSTALL_DIRECTORY “kodi 0.0.1”)
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY “kodi 0.0.1”)
SET(CPACK_PACKAGE_NAME “kodi”)
SET(CPACK_PACKAGE_RELOCATABLE “true”)
SET(CPACK_PACKAGE_VENDOR “Humanity”)
SET(CPACK_PACKAGE_VERSION “0.0.1”)
SET(CPACK_PACKAGE_VERSION_MAJOR “0”)
SET(CPACK_PACKAGE_VERSION_MINOR “1”)
SET(CPACK_PACKAGE_VERSION_PATCH “1”)
I HACKED/CHANGED to look like this.
SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE “http://kodi.tv”)
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ” “)
SET(CPACK_DEBIAN_PACKAGE_VERSION “2:18.0~git20171214.0453-b4e54bf036-di-1~stretch”)
SET(CPACK_DEB_COMPONENT_INSTALL “ON”)
SET(CPACK_GENERATOR “DEB”)
SET(CPACK_INSTALL_CMAKE_PROJECTS “/share/kodi/build;kodi;ALL;/”)
SET(CPACK_INSTALL_PREFIX “/usr”)
SET(CPACK_MODULE_PATH “/share/kodi/cmake/modules”)
SET(CPACK_NSIS_DISPLAY_NAME “kodi 18.0.0”)
SET(CPACK_NSIS_INSTALLER_ICON_CODE “”)
SET(CPACK_NSIS_INSTALLER_MUI_ICON_CODE “”)
SET(CPACK_NSIS_INSTALL_ROOT “$PROGRAMFILES”)
SET(CPACK_NSIS_PACKAGE_NAME “kodi 18.0.0”)
SET(CPACK_OUTPUT_CONFIG_FILE “/share/kodi/build/CPackConfig.cmake”)
SET(CPACK_PACKAGE_DEFAULT_LOCATION “/”)
SET(CPACK_PACKAGE_DESCRIPTION_FILE “/usr/share/cmake-3.7/Templates/CPack.GenericDescription.txt”)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY “kodi built using CMake”)
SET(CPACK_PACKAGE_DIRECTORY “/share/kodi/build/packages”)
SET(CPACK_PACKAGE_FILE_NAME “kodi-18.0.0-armv7l”)
SET(CPACK_PACKAGE_INSTALL_DIRECTORY “kodi 18.0.0”)
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY “kodi 18.0.0”)
SET(CPACK_PACKAGE_NAME “kodi”)
SET(CPACK_PACKAGE_RELOCATABLE “true”)
SET(CPACK_PACKAGE_VENDOR “Humanity”)
SET(CPACK_PACKAGE_VERSION “18.0.0”)
SET(CPACK_PACKAGE_VERSION_MAJOR “18”)
SET(CPACK_PACKAGE_VERSION_MINOR “0”)
SET(CPACK_PACKAGE_VERSION_PATCH “0”)
You can imaging what deb packages and armv7l directory looked like when set to 0.0.1
Regarding fmt and rapidjson, I submited a patch where you can compile the internal versions by setting -DENABLE_INTERNAL_FMT=ON and -DENABLE_INTERNAL_RapidJSON=ON 🙂
About the other issues I’ll try to have a look at them in the following days 🙂
Thanks for all the input, it’s really appreciated.
Perfect patch suggestion.
Now if we could do something about the ffmpeg situation. Now K18 wants ffmpeg 3.4…..not an issue but I can’t seem to get builds to recognize that I have already done a make and make install on 3.4… I know about the FFMPEG_PATH and WITH_ option and INTERNAL_FFMPEG and such options but I am struggling on making a build use external ffmpeg. I want external so it does not have to wget and compile each time I wipe my build directory.
But just had a thought. I can save off the already compiled ffmpeg stuff from the build directory. ( I’ve been playing so much and making out SD card space that I wipe things a lot…gotta stop that and buy a bigger SD card)
Honestly I never tried to build ffmpeg outside of the normal flow, specially because I mostly use popcornmix’s branches which include patches to optimise ffmpeg to make use of PI’s CPU and GPU internals, making it much more performant and tailored to the Raspberry Pi.
I’ve just tried to compile kodi’s master by using the script I mentioned before, and it worked without any issue. I didn’t need to do any workaround or anything, just checked out plain master branch from xbmc repo, put the script in the root dir and triggered the build. So I’m not sure what happened with your builds before 🙁
Regarding the SD, what I did was to buy a USB3 drive so I compile everything in there, otherwise the risk of wearing out the SD card with so many writes is very high. I didn’t notice any performance degradation, not that Pi supports USB3, but because USB3 drives use really fast flash memory which helps to max out the USB bus instead of waiting for IO to happen.
Regarding this topic of saving the SD card, I wrote a post some time ago with some tips that I’ve been using without any issues so far.
Thanks for all the input once again 🙂
BTW I am trying to compile: git clone https://github.com/popcornmix/xbmc.git
I have/am using/are testing a kodi 18 build on my PI3 Debian Stretch.
I had to overcome many many hurdles to accomplish the build.
Depending on the configuration you might encounter some issues indeed, I’ll try to update the branch with the latest version and compile it.
I can also create a post about how to compile v18, so your input on the things you came across and how you solve them would be interesting.
Thanks
Ok…I give up and must ask for help. I am attempting Kodi 18 build. I have overcome fmt and rapidjson issues but I am stuck on how to resolve the below error. I googled and still cannot find fix.
In your spare time is it possible for you to assist me in overcoming the below issue?
/usr/bin/cc -fPIC -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4 -mvectorize-with-neon-quad CMakeFiles/cmTC_3aabe.dir/CheckSymbolExists.c.o -o cmTC_3aabe -rdynamic
CMakeFiles/cmTC_3aabe.dir/CheckSymbolExists.c.o: In function `main’:
CheckSymbolExists.c:(.text+0x48): undefined reference to `pthread_create’
collect2: error: ld returned 1 exit status
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0ca02.dir/link.txt –verbose=1
/usr/bin/cc -fPIC -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4 -mvectorize-with-neon-quad -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_0ca02.dir/CheckFunctionExists.c.o -o cmTC_0ca02 -rdynamic -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
On a positive note I was able to compile and use another kodi 17.6 build that I made on my Debian Stretch rpi3. (kodi still crashes on my PI. Guess I better submit a ticket to the kodi team.
Thanks in advance, and once I am successful I will help you write a kodi 18 compile blog post if you wish.