FOSS library to include Python code in an Android app

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.)

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

It’s BSD but seems compatible with FOSS.

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.

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.

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.

Maybe check https://www.qpython.com/

Qpython is also on Play store.

Another option is maybe to convert your app in C with converters or via cython.

I thought about qpython but it also seems to be aimed at calling into Java from Python rather than the other way round.

Being pessimistic, I think that the options would be to a) convert the hangups library to Java, b) convert the front-end to Python and use something like Kivy.

There is also QHangups which could possibly be built for Android by using pyqtdeploy. However, it might be less interesting for @Rudloff to port someone else’s app instead of developing his own, especially if the other app might also need a lot of work so that it runs nicely on a phone.

Thanks for the info!
Jep might be the closest to what I need (calling Python functions from Java functions). Now I need to find some time to test if it can work correctly on Android.

I don’t have the experience with Java tools to know if it can be made to work on Android, but you are probably better qualified to investigate, anyway. Good luck! :smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.