Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 438
bdutta74 Avatar asked Jan 17 '15 15:01

bdutta74


People also ask

Can KIVY run on Android?

Kivy can be run on Android phones using the Kivy Launcher (from the Android store) or an APK can be build using Python for Android (see http://kivy.org/docs/guide/packaging-android.html).

How does KIVY work on Android?

Kivy is a Python framework, and simply installing it on an Android device the same way as on a desktop machine will do nothing. However, you can compile a Kivy application to a standard Android APK that will run just like a normal java app on (more or less) any device.


2 Answers

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.

like image 178
inclement Avatar answered Oct 10 '22 04:10

inclement


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

  • Use jython 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 nuitka, which generates C++ code from your Python code. Then use the android-ndk.
like image 42
Tobias Kienzler Avatar answered Oct 10 '22 04:10

Tobias Kienzler