![]() |
Android What is the correct way to import binary modules in Python addons? - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93) +---- Forum: Android Development (https://forum.kodi.tv/forumdisplay.php?fid=184) +---- Thread: Android What is the correct way to import binary modules in Python addons? (/showthread.php?tid=231642) |
What is the correct way to import binary modules in Python addons? - Roman_V_M - 2015-07-09 Me and a couple other guys from Russian Kodi forum try to compile libtorrent-python binary module to use in torrent-streaming plugins in Kodi on Android, but so far our efforts haven't been successful. We were able to get a compiled libtorrent.so file, but it won't load in Kodi addons, probably because Python in Kodi on Android seems to use non-standard mechanism of loading binary modules. At least from what I see here (p. 8) and here. So the question is: how to correctly load Python binary modules in Kodi addons on Android, assuming that the modules have been correctly built with Android-NDK? And, if this is necessary, what changes need to be applied to those modules to use them in Python-Kodi-Android? RE: What is the correct way to import binary modules in Python addons? - Memphiz - 2015-07-09 We do the same with the boblight addon. 1. For building the so correctly you need to do the following at the end: https://github.com/xbmc/xbmc/blob/master/tools/depends/target/boblight/Makefile#L40 2. In the addon you need to ensure to load it via ctype from a location which has the needed android rights. For boblight the so file needs to be here: https://github.com/bobo1on1/script.xbmc.boblight/blob/master/script.xbmc.boblight/resources/lib/tools.py#L108 3. Loading binary so files on android is cumbersome because of android - not because of python... RE: What is the correct way to import binary modules in Python addons? - Roman_V_M - 2015-07-09 As far as I understand, ctypes can be used only for pure C libraries operating with rather simple data types, but not C++ OOP libs dealing with classes and objects. But libtorrent-python is a rather sophisticated Python binary module written in C++ with Boost. On other platforms it is loaded by simple import statement. Or import for binary modules is broken in Kodi-Android? RE: What is the correct way to import binary modules in Python addons? - Memphiz - 2015-07-10 Ohh ok - so no ctypes. Then i don't have a clue. RE: What is the correct way to import binary modules in Python addons? - srg70 - 2015-07-12 Dear Memphiz! Thank you for your suggestion. It was really helpfull. We succeeded to load libtorrent module on Android. Although this post is on russian, the code is international ![]() RE: What is the correct way to import binary modules in Python addons? - Memphiz - 2015-07-12 And what was missing for it to load? RE: What is the correct way to import binary modules in Python addons? - srg70 - 2015-07-12 We were missing preloading of liblibtorrent.so. We just followed your instructions. Before your answer we have missed this code Code: dll_path=os.path.join(dest_path, 'liblibtorrent.so') After we added these lines (with liblibtorrent.so) a regulat python's load method began to work for libtorrent.so also. I assume there is some low-level cache for loaded libraries that now contains a liblibtorrent.so. Therefore import is succeded. RE: What is the correct way to import binary modules in Python addons? - zachmorris - 2016-12-19 I came across this thread after fighting with my addon for a good while, trying to make a binary execute on a non-rooted FireTV stick. I'm mostly convinced it won't work due to permissions, but I thought I'd ask. I have a command line binary compiled for android (p7zip / 7za, for de-compressing 7z files). Including the binary and command line os.system execute commands in my addon seems to work just fine for every other system I've tried, but Android is a different animal. I've attempted to execute the binary in the following locations: /data/local/tmp/ - copied the file to this location and I can execute it via adb, but it fails when attempting to execute from my Kodi addon (using os.system or subprocess) /data/data/org.xbmc.kodi/files/ - copied the file to this location and I can't execute it via adb (permissions error) or the addon Is it possible to run a command line binary in android from Kodi? If so, what is the proper location to put the binary? Second question, if the first isn't possible. I assume if I could compile a "libp7zip.so", ctypes is the correct method to use in Kodi / python and /data/data/org.xbmc.kodi/files or /data/data/org.xbmc.kodi/lib is where the library should be located? What is the correct way to import binary modules in Python addons? - Memphiz - 2016-12-20 Yes to the latter |