This is an introduction to my series of articles that describe how to build binary Python modules for Kodi addons on Android platform.
Kodi mediacenter includes a full-featured (well, almost ) CPython interpreter for creating plugins. CPython, which is the reference Python implementation, in its turn provides the Python/C API that allows to create a binary Python extension modules in C language. These module are used, for example, to speed-up some CPU-intensive tasks, because Python, being an interpreted language, is relatively slow.
Another possible use case for binary modules is hiding some proprietary algorithms. It won't give you 100% protection from a clever hacker but extracting info from a compiled binary library is much harder than from a .py
file which is basically a plain text. As far as Kodi concerned, closed source addons will violate GPL v.2 terms, but technically they are possible.
There are a number of popular Python packages that include binary modules: NumPy, matplotlib, Pillow, lxml and many others. On desktop platforms obtaining and using binary Python modules are relatively easy. For example, if you run Kodi on Windows and want to use some binary Python module in your addon, you can go to PyPI, download a compiled .whl
for your platform and extract the necessary module with an archiver program, for example 7zip.
However, compiling and using binary modules in Python addons for Kodi on Android is not a trivial task. First, you need to cross-compile such module using right tools and then to correctly load this module in your addon, because in Kodi on Android import mechanism for binary modules is seriously broken and simple import
statement won't work. In this series of articles I will show you how to cross-compile a binary Python module that can be used in an addon for Kodi on Android, and how to correctly import this module from Python. I will also provide a brief overview of 2 convenience C++ libraries that allow to develop binary Python extensions: Boost.Python and Pybind11.
In the 1st part of my series I will cover prerequisites needed for building Python/C extension modules for Kodi Python addons on Android.