Hi all, Per the title, we (the Kivy devs) have just released python-for-android (p4a) 0.4 [1]. This release in particular is a major one because it's the culmination of a lot of recent work rewriting the python-for-android packager to be more general, not just for Kivy's use but to support other kinds of Python apps. I've meant to say something about it here for a while, and this seems like a good milestone to bring it up.
p4a is a packaging tool for bundling Python itself, plus any extra Python modules or other dependencies (including those with compiled components such as numpy or Kivy itself), into an Android project that can be compiled into a normal APK and run on any Android device. On a technical level it's concerned specifically with compiling these dependencies for the Android architecture and environment, so that Python itself runs just the same as on the desktop. This comes with all the standard advantages and disadvantages: on the bad side, Python can be a little slow to start and there's no practical way to build a GUI with native Java widgets (though small numbers of Java widgets can be instantiated and manipulated via JNI). On the other hand, if these aren't a concern (e.g. with games, certain kinds of apps, or just personal preference) the big advantage is that most Python modules work exactly as on the desktop, and even C extensions often require little or no modification. In the past, p4a only supported a basic Pygame backend for Kivy's own use, but we noticed that a number of other projects were forking the build tools and having to hack out the Kivy-specific bits (duplicating a lot of work) to build other kinds of application. p4a now is a much more general packager supporting multiple bootstrap types, each holding the Java and Android project code to start Python and create a specific kind of GUI. These currently include SDL2 (works with Kivy or other wrappers like PySDL2 or Vispy), a webview bootstrap for use with e.g. a Flask backend, and Kivy's old Pygame backend. It's also possible to build a gui-less Python script, and there's some preliminary support for exporting the Python build for use in mainly-Java apps. Other projects can now use p4a by just adding or adapting bootstrap code to their purposes, and nothing depends on Kivy (or much else). The rewrite has also removed some long-standing limitations and allowed adding some important new features. These include experimental support for Python 3 apps via the CrystaX NDK [2] (whose additions to Google's NDK allow Python to compile without patching even on older Android versions), support for multiple architectures, and a much improved internal infrastructure to make supporting new compiled dependencies much easier. Looking to the future, there are still plenty of things to fix or improve about running Python on Android this way. Building Python (2 or 3) is made much easier with CrystaX even without the recent improvements in Android's libc or in Python itself (I'll admit I'm not too familiar with the current state of Python patching for Android builds), but these parts of the toolchain need work to be as stable as the old patched Python 2.7. Using platform-specific APIs can be pretty easy with JNI wrappers like pyjnius or rubicon-java, but it can also be annoying and it would probably be preferable to support more of them with Python API wrappers like Plyer [3] instead. And of course, python-for-android is still based around compiling everything locally, contributing to the fact that it doesn't work on Windows and meaning that even on Linux or OS X the process is more laborious than really necessary for most users. We've focused on this method because it has to be done somewhere, and binary distribution gets complicated if trying to be clever about dependency options, but a major improvement would be to support precompiled distributions so that users can build APKs without needing to compile anything. I had this in mind when thinking about the new toolchain, partly thanks to Russell setting an excellent example with his BeeWare mobile distribution, so it shouldn't be too hard to start supporting. It may even be possible to be clever about it, using wheels built for Android. So, that's the current state of python-for-android. Any comments, questions or criticisms are very welcome! Best, Alexander [1] https://github.com/kivy/python-for-android [2] https://www.crystax.net/ [3] https://github.com/kivy/plyer
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mobile-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/mobile-sig
