Kivy Python For Android Download
QPython is a program engine that runs Python script on your Android devices. It contains the Python interpreter, editor, QPYPI, QRCode reader and some amazing features for Android. It's literally the most awesome Python on Android. Newest version is 2.4.0, it contains the following amazing features.
It’s been a long time coming, but we can finally make theannouncement… python-for-android now supports Python 3 Android apps!This naturally includes Kivy, but also should work for anything elseyou can package with python-for-android, such as apps made withPySDL2. Using Python 3 remains experimental for now, it works butdoesn’t yet perform all possible optimisations and hasn’t been aswidely tested as Python 2. However, there should be no extraapplication requirements (beyond actually being written for Python 3),and the remaining issues and optimisations are being worked on.
Python-for-android is a packager for Python apps on Android. You can create your own Python distribution including the modules and dependencies you want, and bundle it in an APK along with your own code. Features include: Support for building with both Python 2 and Python 3. Different app backends. Aug 19, 2019 python-for-android. Python-for-android is a packaging tool for Python apps on Android. You can create your own Python distribution including the modules and dependencies you want, and bundle it in an APK along with your own code. Features include: Support for building with both Python 2 and Python 3.
Overview
python-for-android isa packaging tool for turning Python applications into Android APKs. Itwas originally created to make apps with the very cross-platform Kivygraphical framework (though it didn’t arise in avacuum, I think it built in particular on previous work by the Ren’Py project). However, the original python-for-androidhad flaws including being quite inconvenient to modify for non-Kivyapps (several other projects seem to have used modified versions, buteach was performing similar changes), hard to extend for multiplearchitecture support, hard to extend internally (both in general andfrom the perspective of new contributors, as much of the toolchain was abig shell script), and only supported building apps with Python 2.
We recently completed and released a fully revamped version ofpython-for-android aimed at fixing all of these problems, as discussedin several previous posts on this blog (originally here). Almost all of the originalgoals are now complete, with Python 3 support the major missing oneuntil now, though not for lack of trying. Some technical details andbasic instructions for testing the new support are given below, andyou can also see the online documentation for further information.
Our Python 3 support depends on the prebuilt Python distributionsprovided with the CrystaX NDK, adrop-in replacement for Google’s own Android NDK with many fixes andimprovements. The technical details of this choice are given below,and we’ll try to further support a locally-built Python 3 option in thefuture. Thanks to the CrystaX team for making it so (relatively) easy!
Technical details
python-for-android works by bundling a Python interpreter, compiledfor Android devices and architectures (usually arm, though otherchoices are supported), into an Android APK. The APK includes a simpleJava bootstrap application, which mostly starts a Python script viaJNI. The script then runs essentially as normal, almost all of thePython standard library is present and works fine, andpython-for-android supports including other modules or non-Pythondependencies. Pure Python modules will mostly work without specialtreatment, though things requiring compilation need a specialrecipe. Many common modules such as numpy and sqlalchemy are supportedthis way. Following its revamp python-for-android is now designed tosupport multiple kinds of java bootstrap, but the current main supportis for GUI apps via Pygame (for Kivy’s old Android support) or SDL2(both for Kivy and for anything else that can use it); SDL2 also nowdoes much of the heavy lifting of handling events etc. itself, via itsown Android support.
The main problems with compiling and including Python are first thatit must be patched to compile (as Android’s libc doesn’tsupport some things very well or at all), and second that it must beunpacked and started on the device via its C API. The second point isfiddly but ultimately not that different to working this way on thedesktop. The first is (in my opinion) harder because it needs someunderstanding of Python’s internals, of Android’s limitations, ofappropriate fixes, and of how to test and debug these problems.
Such patches have been made by a number of different people fordifferent Android versions, and I believe there has been activity onPython itself to fix some issues (including this current issue to make Python build nativelyon Android). For Python 2, I think python-for-android’s originalpatches came from here,though extended with further modifications. However, the main thingholding up my efforts to get Python 3 working was the inability to finda similar working patchset; I tried a few sources, achieving a workingcompilation using SL4A’s python3 patches,but I couldn’t get Python working on the device. I’m sure this was myown technical mistakes, since other projects do have it working, butit’s what was holding up the feature.
I eventually resolved this by using the new Python on Android supportfrom the CrystaX NDK. As mentionedabove, this is a drop-in replacement for Google’s own NDK (the NativeDevelopment Kit providing compilers etc for targeting Android withnon-Java code), including many improvements to the buildenvironment. As of version 10.3.0, they provide prebuilt Pythonpackages for Android on all architectures - and all of their NDKimprovements mean that Python no longer even needs patching for thiscompilation to work. Python is provided as a zipped standard library(Python can automatically load modules from zip files), and a folderof the compiled components like ctypes (as it’s hard to dynamicallyload from zips). From the perspective of python-for-android,supporting Python 3 means modifying the build to load CrystaX’sprebuilt components (both in the Android project structure and inpython-for-android’s support for compiling other modules), andmodifying the C initialisation code for Python 3. This takes somework, but all told wasn’t very hard and the Python bundles worked withno issues, so we owe a lot to CrystaX; thanks again.
I’d still like to come back to the issue of local python3 compilation;CrystaX’s versions are fine, but I’ve learned a lot from making themwork, and have a much better idea of what I may have been doingwrong. However, the focus for now will be on resolving the remainingissues with what’s already working.
Building apps with Python 3
Building Python 3 APKs is only supported in the revampedpython-for-android toolchain which was merged to the master branch awhile ago. It can be installed and used as described in itsdocumentation. Ifyou use Buildozer, it currently does not support this new toolchain,though tito has been working on this. There is also the newrestriction that you must (for obvious reasons) use the CrystaX NDK,which can be obtained here;simply refer to its filepath when setting the NDK directory, andeverything else should work automatically.
To build for Python 3, add the python3crystax recipe to therequirements option,e.g. --requirements=python3crystax,kivy
. It should mostly workautomatically with existing recipes, though at this stage theremay be bugs or problems with a few, and some will needmodification. The exact syntax above may also change in the future asthe Python 3 support becomes better integrated, but not significantly.
There’s also one big change whose importance I’m not sure about; thePython 3 mechanism doesn’t currently build a local Python 3 to use as ahostpython, instead using the system python. This means that you musthave python3.5 (3.4 may also work) installed locally in order forpython-for-android to build Python 3 APKs. This will be fixed soon,adding a hostpython3 recipe to avoid weird bugs with system-specificdifferences, but you need to bear it in mind for now.
Future work
For now, this Python 3 support remains experimental. I anticipate nomajor issues, but it’s internally a quite different method to thePython 2 support and needs further work to duplicate some of the oldoptimisations, and undoubtedly to fix bugs in the toolchain that willappear as it stabilises. Amongst other things, Python 3 sharedlibraries are not currently collected and merged (with Python 2 we didthis originally to get around an Android limit but also foroptimisation), python files are not precompiled to bytecode (it canmake a big loading speed difference), and some features of the oldpygame bootstrap have not yet been implemented in SDL2. All this andmore will come in the future, but shouldn’t be hard to add now thatthe toolchain all works.
The SDL2 bootstrap is also missing a few features that users of theold toolchain will be used to, like the splash screen image and atleast one Kivy-specific function. These too are being actively workedon, especially as more people start to move their apps to SDL2.
I’ve also phrased this as Python 2 built locally vs Python 3 fromCrystaX, but actually CrystaX also supports Python 2.7 and I hope toadd this option in the near future. As discussed in the technicaldetails, it also should absolutely be possible to have a local Python 3build, which I’d like to eventually come back to.
A natural question when people hear about Kivy as a way to create Android apps in Pythonis…what can you do with it? Is it performant enough for games, canyou call the Android APIs, do all apps look the same? One of the bestresources for these kinds of question are existing apps, and in thispost I’ll give a quick impression of three of my favourites. This isobviously highly subjective, but I’m focusing in particular onfeatures of technical interest, apps that push Kivy beyond what’snormal to show what it capable of.
If you’re interested in other examples, there’s a fairly extensive(but far from exhaustive) list on the Kivy wiki,including winners of our programming contests and many contributionsfrom users. If you’d like to make your own apps in Python, check out Kivy (which also runs on Windows, Linux, OS Xand iOS) and python-for-android (which canalso package non-Kivy Python apps).
Boardz
You can download Boardz here.
I’ve put Boardz first because it’s my single favourite Kivy app. It’sactually a work in progress (and in fact hasn’t been updated for awhile), but is already a fun game showcasing some of Kivy’s moreimpressive performance potential.
Boardz homescreen (left) and gameplay (right). The black ring onthe right is the input circle controlling rider posture.
Boardz is a snowboarding physics game; you control your snowboarder bytouching the screen, then moving your finger with respect to itsinitial position to control your posture; quick movementsthrow your weight around and can cause you to jump, spin, or fallover, while just positioning the rider differently helps you to pickup speed or navigate barriers. The objective of the game is to get tothe end of each stage, with different obstacles includingslopes and jumps, collapsing structures, falling rocks, or evenmultidirectional gravity and rocket boosters. You can fail if yourhead collides with another object with too much force, or if yousimply get stuck and can no longer reach the finish.
What’s immediately impressive is that all this runs well as a Pythonpowered game running on a smartphone. It achieves this by being builtusing the KivEnt game engine developed byJacob Kovac, one of Kivy’s core developers. This entity based systemlets you write game code in Python but internally is highly optimisedin Cython, using Kivy’s OpenGL API extremely efficently as well asinterfacing with the popular Chipmunk Physics engine.
Boardz wipeout failure by fatal collision (left), and an ad (right).
Boardz betrays its in-progress nature in other ways; you can see inthe above screenshots that its UI isn’t very polished, and in thissense it’s the worst of the apps I’m showing here. However, it makesup for this with its surprisingly engaging gameplay, and a breadth ofentertaining features not showcased here, including leader boards,racing your ghost, and different riders with different physics attributes.
A final technical feature interesting to Kivy app developers is thatBoardz includes ad integration. Regardless of your feelings about adsthemselves, the ability to use them is a major feature enquiry fromnew Kivy users. The problem here is that integrating with a normal adprovider normally requires adding to the Java components of your app,which it may not be immediately obvious how to do from Python. Thereare actually a number of resources for this nowadays, with a key pointbeing that python-for-android tries to makeit easy to include extra Java code, with which you can interact fromPython using Pyjnius. KivEnt’simplementation, pictured above, is a nice demonstration.
Kognitivo
You can download Kognitivo here.
Kognitivo is perhaps the single most polished Kivy app on the Playstore, being relatively complex, extensively customised, andexhibiting a number of nice Android API interactions. It is also(deservedly) possibly the most popular Kivy app on Google Play.
Kognitivo tutorial (left), game instructions (centre) andhomescreen (right).
Kognitivo is a brain training and performance monitoring app. Thebasic structure is to perform a series of simple exercises intended totest different aspects of cognitive performance, being rated onaccuracy and speed, and with the results compiled over time in orderto detect and act on trends.
As I’ve said already, the nice thing about Kognitivo is its huge amountof polish. It is extensively themed such that no trace of the Kivydefaults remains, runs extremly smoothly, and includes many niceanimation tweaks (unfortunately not captured in screenshots) to feelresponsive and active.
Kognitivo training game (left), Android notification (centre) andin-app purchase option (right).
On the technical side, Kognitivo exhibits a number of features notnormally included in Kivy applications but possible throughinteraction with the Android API via some Java code and/or theaforementioned Pyjnius. These include notifications, interaction withyour calendar, and in-app purchases.
The author of Kognitivo, Sergey Cheparev, has his own writeup ofKognitivo’s development on his blog, includingdiscussion of the advantages and disadvantages of Kivy development,and of the experience of putting together all these features. This isa great resource on its own; I don’t agree with some of the author’scriticisms and some of Kivy’s features have been improved since then,but it’s an excellent overview of the experience. Most of all, heenthusiastically captures some of my own reasons for finding Python onAndroid interesting:
I think the most beautiful thing in it is to use the almightinessof [Python]’s frameworks. I used sqlalchemy and sqlite as abackend, and it worked like a charm! Python is the most powerfulllanguage because of it’s frameworks, you can even start Django onyour smartphone! It’s amazing! Or twisted for asynchrocommunication with server. Or nltk for in-app natural languageprocessing. Or maybe you want make a mobile equations solver withscipy and numpy. This makes all the dreams come true.
Barly
You can download Barly here,or visit its own website.
Barly is the most recent of these apps to appear on Google Play. I’vechosen to include it as a nice example of pulling off its conceptquite well while making good use of Kivy; like Kognitivo the app isthemed very differently to Kivy’s defaults (though it doesn’t looklike a normal Android app either), and is generally well put together.
Barly homescreen (left), palate options (centre) and a beer searchresult (right).
To quote its Google Play blurb, Barly is ‘your personal beerexpert’. It provides a convenient interface to browse beers via datafrom standard popular websites, and according to your description ofyour own palate. Barly’s most interesting feature is the ability totake a picture of a beer menu and have it automatically detect whatbeers are listed, followed by downloading information about them tohelp you choose. That kind of image analysis has to be tricky, butactually didn’t perform badly when I tested it.
The interface to this functionality is quite nice, switching to theAndroid camera app to get the image before uploading it to a serverfor processing (during which you can input your preferences). Thisfunctionality is possible with Pyjnius as mentioned previously, butactually in this case is an API also exposed in pure Python by Plyer (another Kivy sister project,wrapping platform-specific APIs in a Python frontend). Not all APIscan be conveniently exposed this way, and actually Barly may not evenbe using this particular method, but it’s a good example offunctionality that can be achieved with Kivy in a particularlycross-platform way. Free download vlc media player for samsung android mobile price in bangladesh.
Kivy Android App
Beyond this, Barly does not make such wide use of the Android API orunusual Kivy features, but nor does it try to; it is a nice example ofa complete and self-contained Kivy app using the power of Python foran unusual and interesting goal.