QPython or Kivy for Android programming with Python - producing installable apk
Asked Answered
B

2

25

Having read several Q&A's on SO, I realize that one has 2 options i.e. QPython and Kivy to do programming for Android, however, apparently both take different approaches. I am trying to validate my understanding and see if I am missing some key piece of information.

  • QPython allows usage of Kivy library for developing graphical applications
  • QPython and Kivy both use SL4A, while QPython has expanded standard SL4A (or it's bindings for Python) by adding some NFC and similar functions
  • QPython is used to create python scripts that can use wide range of modules, libraries, but they need QPython installed to be executed on target device. There is no way to package script into an apk.
  • Kivy OTOH, allows developer to write applications that compile to apk, using their cloud based build system (alternative - local build system can be set up on Ubuntu Linux) [However, I noticed that most of the sample apk's that use Kivy are pretty large, in the 40MB range. Did I miss anything ?]
  • QPython apk has 2 version i.e. one for Python-2.7 and another one for Python-3.x. For Kivy, I'm not sure which version it is.
  • QPython example script (HelloWorld.py) doesn't seem to behave as expected, from latest QPython-3.x from Market, on an Android Kitkat (4.4.2) system. I get the dialog to enter text, but then I expect a Toast to popup, but nothing happens.
  • Get the impression that both QPython and Kivy are developed by a single developer each (or only one person is really active at present), and don't yet have a biggish community. [This is my biggest concern] I notice that there are 3-4 questions with 'qpython' tag on SO, and more than thousand with 'kivy'!
  • Also get the impression that at this moment Kivy development is somewhat more active (perhaps quite active), but for QPython I don't have a clear picture.
  • Kivy seems to be trying to expand the nature of application that could possibly be written using it, compare to QPython. There are API's like plyer and pyjnius that help expand the possibilities. Perhaps quite significantly, compared to QPython.
  • Both QPython and Kivy seem to be heavily under development. Program (/ script) crashes (/ failures) seem to be reported on both set of tools.

Overall, the opinion as a result (of above points) appears to swing in favour of Kivy, a bit more. Is the understanding correct ? Did I miss any crucial point ? This is not a rhetorical question, and I am looking for factual answers only.

Bearcat answered 17/1, 2015 at 15:38 Comment(0)
T
16

QPython allows usage of Kivy library for developing graphical applications

Yes, qpython is an interpreter + associated tools, and has some nice kivy integration. You can't compile the kivy code to a standalone apk with qpython+android alone though.

QPython and Kivy both use SL4A, while QPython has expanded standard SL4A (or it's bindings for Python) by adding some NFC and similar functions

Kivy does not use SL4A. We achieve android api integration mainly through pyjnius, a library for automatically wrapping java classes with python, which lets you call the java api directly. We also have abstracted some standard things to a pythonic interface with plyer.

(I saw later that you already have found these)

QPython is used to create python scripts that can use wide range of modules, libraries, but they need QPython installed to be executed on target device. There is no way to package script into an apk.

I don't use qpython much, but I think this is correct, although there may be some tools turn scripts to apks in some circumstances (e.g. you could use kivy's build tools if you have a kivy interface, or maybe sl4a has something for this).

Kivy OTOH, allows developer to write applications that compile to apk, using their cloud based build system (alternative - local build system can be set up on Ubuntu Linux) [However, I noticed that most of the sample apk's that use Kivy are pretty large, in the 40MB range. Did I miss anything ?]

We have a basic cloud based build system but nothing else like that right now, almost everyone builds apks on their own machine using our build tools for android. These run on linux or OSX, and can easily be run in a virtual machine if necessary.

A minimal app has about 7MB APK size due to the necessity of bundling the python interpreter and a lot of modules.

QPython apk has 2 version i.e. one for Python-2.7 and another one for Python-3.x. For Kivy, I'm not sure which version it is.

Kivy itself supports python3, but our android build tools only support python2.7 for now.

Get the impression that both QPython and Kivy are developed by a single developer each (or only one person is really active at present), and don't yet have a biggish community. [This is my biggest concern] I notice that there are 3-4 questions with 'qpython' tag on SO, and more than thousand with 'kivy'!

Kivy development is quite active with several regular contributors plus more sporadic ones. You can see for example recent commit activity on github. It's certainly a lot more than a single developer!

Kivy seems to be trying to expand the nature of application that could possibly be written using it, compare to QPython. There are API's like plyer and pyjnius that help expand the possibilities. Perhaps quite significantly, compared to QPython.

I think qpython includes pyjnius. Not sure about plyer.

Both QPython and Kivy seem to be heavily under development. Program (/ script) crashes (/ failures) seem to be reported on both set of tools.

I'm not sure what you're looking at, but any non-trivial project will have crashes/failures/bugs reported. I don't think kivy is particularly inherently unstable.

Overall, the opinion as a result (of above points) appears to swing in favour of Kivy, a bit more.

I would have said that qpython and kivy are quite different things. Qpython lets you write and run scripts, while kivy is a graphical framework and associated tools to create standalone apps. There's some overlap with tasks that could be achieved with both of them, but also plenty of things where they are not both suitable - for instance, I think qpython is probably much more convenient to make quick scripts with no gui for e.g. simple automation (I think this is possible), whereas I think kivy is a far better choice for creating standalone apps with non-trivial guis. Of course you can write kivy code in qpython, as discussed, but this isn't a great user experience for anything non-trivial and you need a desktop/laptop machine anyway to make a standalone apk.

Tressatressia answered 17/1, 2015 at 15:59 Comment(13)
Thanks for the detailed response. Picture is definitely clearer now. If not SL4A, I guess both QPython and Kivy use 'Python for Android', although so far I don't have much of a clue as to what that is, and if might be another name for SL4A ? I saw note about commercial support being available in future, for kivy. Is there a know ETA (even rough estimate) ? Would it change the licensing of kivy in anyway ? I.e. go dual-license or something similar ?Bearcat
Also, the answer on the subject of build environment (being cloud-only), does it mean that the prebuilt Virtualbox image do not work as expected, for now ?Bearcat
The virtualbox image should work fine, though it's currently a little out of date and we will probably update it soon.Tressatressia
There are actually at least two python-for-android projects, one from sl4a and one from kivy. Kivy's one builds apks from kivy apps. Qpython uses the android bootstrap parts to let you run kivy apps (at least I assumed it does), but maybe uses sl4a's one too, I don't know the nature of its python installation.Tressatressia
For commercial support, you can already ask for it and some of the devs do this professionally, though I don't know any details. The license is already fine (very permissive).Tressatressia
Excellent... so it is cloud-build for now. And, thanks I understood the python-for-android project purpose after reading this. Great to know that commercial support is available if required.Bearcat
No to cloud build, almost everyone builds locally! Are we using the term to use two different things here? We have android.kivy.org but it doesn't get a lot of use and may not be reliable, and one of the devs (tito) has a cloud build service in alpha/beta, but this is not the primary way people build kivy apks.Tressatressia
I'm sorry, I misread the point about build environments. Clear now.Bearcat
@icarus74, for productivity Android apps, does it make any sense to have an APK that combines Python 3.4 for everything not-GUI, and JavaScript Cordova for the UI? The GUI need only look/feel native plus touch have capability, ideally the APK should be packaged run after installation without requiring users download a chain of depencecies. have no plans to go cross-platform with iOS. Windows 8+/Linux Ubuntu 14.04 are cross-platform environments I might try to target later.Bifoliate
@codeReview, that sounds like a potentially good approach, though I am not quite sure if there is an obvious way to bridge Kivy/Qpython native part, and Cordova, unless someone writes (or has already written) a plugin. This is especially good where lot of business logic, can be written / already exists -- written in python, and user-interaction is only occasional. Anyhow, something worth exploring.Bearcat
I've been working on a revamped python-for-android. Amongst other things, it supports multiple backends, and it should be quite easy to create one where the python backend uses e.g. flask with a webview frontend using html and javascript.Tressatressia
I concern about modules: numpy, scipy and matplotlib. They're only support numpy. So I can't make my work move onMasson
Matplotlib is probably fairly easy to run on android, we have just had a gsoc project on it so some of the work is done. I think scipy support is unlikely though.Tressatressia
K
3

There are at least two more (though to my knowledge only theoretical) ways of getting Python code running on Android:

  • Use and convert the Java bytecode to Dalvik, as mentioned elsewhere. Unfortunately, not all CPython libraries, e.g. numpy, are available for jython, and if you use Java libraries keep in mind that Android doesn't provide the same ones as e.g. the Desktop JRE
  • Use , which generates C++ code from your Python code. Then use the .
Kymberlykymograph answered 2/3, 2015 at 9:22 Comment(2)
Thanks for answering Tobias. Reading the linked SO Q&A, it appears that jython is only a theoretical possibility which was later proven to be a nearly impractical approach. Unless, of course, I missed something. Thanks about the tip-off on Nuitka, in general. Never knew that it existed, and it is mighty interesting for situations where performance matters.Bearcat
I wouldn't call jython an impractical approach, merely an untested one (that is therefore probably tedious to get working) which I plan on changing at some point in the not-too-distanct-future... Concerning performance optimization, you should also check numpy (or PyPy, Cython and possibly Shedskin)Kymberlykymograph

© 2022 - 2024 — McMap. All rights reserved.