FOSS library to include Python code in an Android app


#1

Hello,

I am currently working on HangupsDroid, a port of hangups to Android.
hangups is a Python library so I needed a way to call from my Java code. I used Chaquopy for that. It works great and is easy to setup but is not FOSS, so my app can’t be included in F-Droid.

Do you know any FOSS alternative I could use to include Python code in my app?

(I had a look at this list but did not found anything that does what I need.
VOC works great for self-contained Python classes but does not seem to fully handle dependencies.)


#2

Did you try Beeware???
https://pybee.org/

It’s BSD but seems compatible with FOSS.


#3

Yes, I tried VOC, which is one of the BeeWare tools. But like I said, I couldn’t make it work with complex dependencies.

Briefcase is also interesting but it seems to use VOC under the hood so it probably has the same limitations.


#4

Maybe check the forks but don’t trust too much transpilers.
This can work (on some android versions) but the generated code can be very ugly, heavy, slow and may not support latest android versions (Android 8).
Rem: currently, I’m facing the migration to Android 8 (the new target of Google), it’s sometimes very difficult even the code is in java. I can’t imagine if it’s from another language.


#5

Is the problem that you need to call out from Java into Python code running in CPython? I guess it should be possible to use Kivy but maybe only in theory. It allows Python code to call into Java from Python using PyJNIus (docs). I don’t know about the other way round. You could ask on their mailing list.

VOC from Beeware should let you integrate Python and Java but it’s a work in progress.

I searched a bit and found Jep which, according to their FAQ, might work on Android but hasn’t been tested. Meanwhille, this article is an interesting tutorial about embedding CPython in an Android application but it might not be a ready-made solution.