Android What is the correct way to import binary modules in Python addons?
#1
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?
Reply
#2
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...kefile#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....ls.py#L108

3. Loading binary so files on android is cumbersome because of android - not because of python...
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#3
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?
Reply
#4
Ohh ok - so no ctypes. Then i don't have a clue.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#5
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 Smile .
Reply
#6
And what was missing for it to load?
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#7
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')
liblibtorrent=CDLL(dll_path)

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.
Reply
#8
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?
Reply
#9
Yes to the latter
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply

Logout Mark Read Team Forum Stats Members Help
What is the correct way to import binary modules in Python addons?2