Each Answer to this Q is separated by one/two green lines.
I’m new to android development, and I have had some experience with Java, C#, Python, etc. Python being my favourite, I’d like to code Android app with it.
Then I saw this question:
Is there a way to run Python on Android?
The most voted answers mentioned
ASE(which is now
SL4A and includes
However, after some googling, I wasn’t able to find any useful info about the difference between
PY4A. Searching for difference between
SL4A was fruitless, too.
So, as for
can someone explain, in easy terms:
– What are the similarity and difference between them?
– What are their good and bad parts?
– Are there any other good alternatives?
Confusingly, there are two projects called ‘python for android’.
SL4A lets you run python scripts on android. Their PY4A is a step in their toolchain, but I don’t know much about it. I understand there is some integration with android apis (you can use some hardware etc.), but limitations in how to run the programs (they aren’t full apps, no gui etc.). This is stuff I infer from seeing other posts, I haven’t tried it, don’t take my word on the details. (Edit: actually it seems there is some ability to package apks and multiple ways to create a gui, I don’t know the details)
Kivy is a graphical framework that supports many operating systems (linux, windows, osx, android, ios, maybe more already). You use it to build python guis. The kivy project also started their own python-for-android project which provides ways to compile the python interpreter for android and to package it as an actual android app (including java api integration with pyjnius etc.). Kivy is well integrated with it so that you can easily compile a python gui app for android, though I don’t think this python-for-android is limited to kivy apps.
So, they are completely different projects that happen to have a component with the same name. SL4A is for running python scripts on android, I don’t know much about its limitations or details. Kivy is a python graphical framework (not limited to android) that can be compiled via its own different python-for-android project to fully integrated gui android apps.
I’ve found this very useful (and recent):
Embedding Python in Android (Tutorial series)
It describes how to embed Python in an Android app, using the Kivy-related Python-for-Android, but not Kivy itself (which isn’t really described in Kivy’s nor Python-for-Android’s documentation, as far as I found), which is useful in various scenarios (e.g. existing Java app, using native GUI directly, etc.)
Since Kivy’s Python-for-Android is more actively developed than SL4A(ASE)’s Py4A, it seems to me the way to go.
(I think it would be very relevant also, and probably more appropriate, to Is there a way to run Python on Android?, but to answer requires more reputation than I currently have.)
To the point of the original question: the most relevant difference I see between Kivy’s Python-for-Android and SL4A(ASE)’s Py4A is that the latter is still today offered as “alpha quality”, while the former seems to be far more active.
Of course if you take Kivy as a whole, it’s a cross-platform GUI library.
Also, the results of my research on the various solutions:
- Google’s Py4A + SL4A(ASE) : used but alpha quality, not actively developed
- offers Python-for-Android, to call python code from Java
- offers Pyjnius, to call Java code from python
- seems to be actively developed
- there’s the tutorial I linked above to embed into Java Android app
- if interested, the cross-platform GUI (Kivy itself)
- primarily an interactive environment to launch python scripts on Android
- based on Py4A, but Pyjnius (see above) is said to be usable
- embedding into a Java app is available, but somewhat limited: a Python job must be started with an Intent, and results are gathered from the stdout; that means more separation that could be desirable in some scenarios, I think.
- python.org: no mention at all of Android
Have you tried QPython ? It’s a new python for android instance which offers more functions.
In addition to the answers here, I’d add the fork of the original Py4A which seems to be actively developed: https://github.com/kuri65536/sl4a
I can’t vouch for the quality or the ease of use. There are .apks to install so it seems fairly straightforward.