Compiling Kodi and building deb packages – Raspbian Jessie
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 Jessie installation, if that’s not your case feel free to skip some the initial steps.
Step 1: Install and Configure Raspbian Jessie
I’m not going to discuss on how you should install Raspbian Jessie 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 libmysqlclient-dev libnfs-dev libogg-dev libpcre3-dev \ libplist-dev libpng12-dev libpulse-dev librtmp-dev libsamplerate-dev libsdl2-dev \ libsmbclient-dev libsqlite3-dev libssh-dev libssl-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, libcrossguid-dev, libgif > 5.0, 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, libcrossguid-dev libgif-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#/jessie/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#/jessie/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
libcrossguid-dev
This is not needed anymore, as we can use the built in crossguid from kodi. If you’d like to use your own, please set -DENABLE_INTERNAL_CROSSGUID=OFF
in the cmake arguments below.
libgif > 5
Kodi depends on a libgif greater than version 5, which is not provided by raspbian jessie. However it is available on some mirrors and it can be downloaded and installed.
wget http://mirrors.fe.up.pt/raspbian/raspbian/pool/main/g/giflib/libgif-dev_5.1.4-0.4_armhf.deb wget http://mirrors.fe.up.pt/raspbian/raspbian/pool/main/g/giflib/libgif7_5.1.4-0.4_armhf.deb sudo dpkg -i libgif7_5.1.4-0.4_armhf.deb libgif-dev_5.1.4-0.4_armhf.deb
libbluray-dev
Kodi needs a version of libbluray which is not available on stock raspbian jessie. 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 😀
What would have to change to make this work for raspian stretch on a raspberry pi 3 b+? I need to make a build with x11 support.
Stretch tutorial: http://blog.nunosenica.com/compiling-kodi-and-building-deb-packages-raspbian-stretch/
Nuno, I have finally overcome a full 12 hours worth of issues w/a Kodi 18 compile and a cmake –build is running now.
Will keep all advised.
I’m happy you did it 🙂
I forgot to mention but I have this script that builds v18, maybe it can help on your future attempts.
https://github.com/PIPplware/xbmc/blob/leia_new/build_rpi_debian_packages.sh
That branch is a bit outdated, I’ll try to update it in the next days, it includes newclock5 popcornmix’s branch and latest v18 (when up to date).
Thanks very much for this guide. I have been experiencing so many crashes w/Kodi 17.1,2,3,4 and 17.5 and I wanted to take advantage of recent bug fixes from Team kodi but a Kodi 17.6 for my Debian-stretch/Raspbian was not available.
I have successfully compiled my own Kodi 17.6 on my Pi3 using this guide and looking forward to a more stable Kodi environment.
Also, you weren’t kidding about the “get some refreshments because this is going to take a while ” comment. My first compile took forever and aborted many times before final success. Now subsequent compile times are very short.
Looking forward to a Kodi 18 compile guide.
Hi Paul, thank you very much for your kind comments. They’re very much appreciated.
Compiling v18 isn’t that much different honestly, maybe a few dependency here and there if any. There is only a difference in paths, which is pointed out in the guide.
Just give it a go and let me know how it went, if there is significant changes I’ll certainly will do a new blog post targeting specifically v18.
When i try to compile xbmc-master v18 and with your tutorial don’t work.
Can you create tutorial to compile xbmc-master v18 on raspberry pi 3 ?
Thanks.
Thanks for your comments.
This tutorial doesn’t cover xbmc 18, I’m working on a new post to compile v18, but it is not ready yet, a few PRs that I haven’t submitted yet are needed to make it work.
I use the official tutorial and my kodi.bin stayed with 400mb. I Compiled in Ubuntu x86. https://github.com/xbmc/xbmc/blob/master/docs/README.raspberrypi
It is advisable, in my opinion, to compile it either natively or in a chroot environment. Most probably your build has too many libraries built-in and is not making use of the shared libraries available in the system. While it can be good in some cases, I think that for Kodi it is better to use shared libraries, as they can be updated on their own without recompiling kodi.
You can share your binaries of kodi v18 for raspberry pi3 ?
I don’t have any up to date ones, if I have any at all, I’ll try to compile v18 and I’ll let you know how it went.
Leonardo, from what I have seen in my attempts to compile Kodi 18 on debian Stretch Pi3 there are significant differences from compiling Kodi 17. I am trying but having issues compiling Kodi 18 but when I get them ironed out I will pass my experiences on to you.
I’m getting this error building kodi:
build/music/tags/music_tags.a(TagLoaderTagLib.cpp.o): In function `CTagLoaderTagLib::Load(std::string const&, MUSIC_INFO::CMusicInfoTag&, std::string const&, MUSIC_INFO::EmbeddedArt*)’:
TagLoaderTagLib.cpp:(.text+0xebac): undefined reference to `TagLib::Ogg::Opus::File::File(TagLib::IOStream*, bool, TagLib::AudioProperties::ReadStyle)’
Are you sure installing libtag11-dev from jessie is okay? That appears to be version 1.9.1-2.1, whereas kodi’s taglib is 1.11.1
I honestly don’t recall any issues with taglib, could it be that maybe taglib was bumped recently in Kodi ? I’ll need to investigate this, I’ll reply back here when I have a solution for it.
Thanks for the feedback once again.
Never had an error/warning also using libtag1-dev from Jessie (1.9.1). Using your krypton_rbp_backports. Which branch are you using ?
I’ve just checked where I compile Kodi and the lib I have installed in libtag1-dev from Raspbian jessie. I’ve never encounter that issue before. Which branch are you using ? Are you following these exact steps ? Can you also provide the output of `apt-cache policy libtag1-dev`?
I’ve also checked Kodi and cmake depends on taglib >= 1.9 (here).
I’m using krypton_rbp_backports.
(BTW I’ve pushed a fix for the ffmpeg / qasm build issue on backports).
Thanks for the fix 🙂
To be able to compile your krypton_rbp_backports branch with ffmpeg optimisations enabled you’ll need to call cmake in the following way:
I’m planning to submit a PR to your branch to include this change.
Regarding your specific error, I don’t have a clue why it happens. I plan to replicate this guide on a clean jessie installation to validate it. Please bear with me for a couple of days and I’ll get back to you.
Thanks.
I found I had taglib in both /usr/lib and /usr/local/lib. I think the /usr/local/lib was from a historical attempt to build kodi.
I’ve zapped the /usr/local/lib one and now the build has completed without errors.
Glad to hear that everything worked out just fine 🙂
Feel free to suggest improvements to this guide.
The libshairplay deb package script link is broken
Some character encoding was messing up with it. It should be fixed now, again.
Looks like a missing dependency for libbluray:
dpkg-checkbuilddeps: Unmet build dependencies: libasm4-java
Indeed it was missing. I’ve added that as well.
Thank you very much for taking the time to test this guide. 😀
Thanks. Another:
E: Unable to locate package xlive-fonts-recommended
I believe it should be texlive-fonts-recommended 🙂 Fixed.
Thanks for the instructions. Some issues I hit running through:
Initial apt-get install:
E: Unable to locate package libxrandprev
Spurious character on end of this line:
git clone https://github.com/Pulse-Eight/libcec.git<
Incorrect download url: http://archive.mene.za.net/raspbian/pool-20160917/unstable/c/crossguid/crossguid_0.1%7egit20150807.8f399e8%7ejessie.tar.xz
missing sudo and strange tag on end of this line:
apt-get install default-jdk javahelper ant doxygen graphviz texlive-latex-base texlive-latex-recommended \texlive-latex-ex
This needs to be url to raw patch, not html page
https://github.com/popcornmix/xbmc/blob/krypton_rbp_backports/tools/depends/target/libbluray/bump_to_Nevcairie_v0.9.2.patch
Thank you very much for your comments 🙂
All the issues you pointed out are addressed and fixed.