briefcase icon indicating copy to clipboard operation
briefcase copied to clipboard

Add support for Kivy, pygame, pyqt, pyside as alternative GUI framework targetting Android and iOS

Open bin-san opened this issue 2 years ago • 16 comments

What is the problem or limitation you are having?

Any thoughts about adding those alternatives? Because briefcase is a packaging utility... I think it should be able to package any python package (including GUIs) to any platform. What do think? Will briefcase ever support those? Because they already run on Android using their own packaging tool called "python-for-android", adding those alternatives to briefcase seems extremely feasible!?

Describe the solution you'd like

GUI Libraries like kivy, pygame uses a surface as a canvas and draw their stuffs. What about NativeActivity in Android? We can use the surface of NativeActivity as a drawing board for those libraries. Packaging tools like python-for-android does the same.

Describe alternatives you've considered

To be clear.. kivy is a mature framework. But it's packaging tool python-for-android follows a horrible strategy by cythonizing whole python and kivy and everything it finds.... taking hours to compile an apk that too crashes on start up... Frustration!!

I adore beeware for it's extremely fast compile time and it's strategy of precompiled binaries.

I would like to see these two work together on Android where I would have versatility of kivy and powerful packaging utility of briefcase.

Additional context

[@mhsmith edit – For now, if anyone wants to use Kivy on Android or iOS, they should use Kivy's recommended packaging tools.]

Related:

  • #452

bin-san avatar Oct 07 '23 15:10 bin-san

How I think we can achieve this:

  1. Creating a simple NativeActivity App which uses A small C program to draw a line on the NativeActivity.
  2. Finding the way to give kivy the NativeActivity as the surface, it will draw on.
  3. Compiling kivy for arm (kivy is open source, so we will have C source code for the parts that is written in C)
  4. Adding all the previous pieces together and combine them to an App.

bin-san avatar Oct 07 '23 15:10 bin-san

First off - we're definitely in support of any changes that would broaden the list of GUI toolkits that Briefcase can support. We're obviously very fond of Toga, but Briefcase is by design not Toga specific.

That said Kivy, Pygame, PyQt and PySide all have very different needs when it comes to iOS/Android packaging.

Kivy clearly can run on iOS and Android; however, I haven't investigated what changes would be needed (on the part of Kivy, Chaquopy, or Briefcase) to make this work.

Qt can apparently run on iOS and Android, but I've never seen an example of it working. (I will also admit that I haven't looked very hard). PySide and PyQt are another story entirely - I haven't seen any evidence that PySide or PyQt can work on iOS or Android. Again - I'm happy to be proven wrong on this front.

I've seen suggestions that PyGame can be made to work on Android with some unofficial patches; but I haven't seen how that is meant to be deployed. I haven't seen anything comparable for Pygame on iOS; however, as you have noted, Pygame is essentially a "draw on a bitmap canvas" API, so solving the iOS problem seems possible.

As for how to tackle this from a technical perspective - each library has very distinct needs, so the approaches will be different. However, what Briefcase encodes is a basic interface: a set of requirements for what an "app" must look like. Fundamentally, this is "a module with a main"; on mobile, it adds an additional requirement of defining a class for OS-level app integration - a UIApplicationDelegate on iOS, and an implementation of an IPythonApp class on Android. Beyond that, it's up to the app. Briefcase provides mechanisms for building and deploy binary wheels, so it should be possible to produce iOS and Android wheels for Pygame, Kivy etc; and, more fundamentally, the bridging libraries (like PyObjUs and PyJNIus used by Kivy).

If you want to tackle integration with any of these GUI libraries, go right ahead. However, be aware that we will be very limited in what support we can provide on the "other" side of the fence. We know almost nothing about Kivy, PyGame, etc; so we're not going to be able to provide much advice on how to resolve issues with Kivy/PyGame internals. What we can advise on is what Briefcase is doing or can do.

freakboy3742 avatar Oct 08 '23 06:10 freakboy3742

I'd like to suggest adding Slint to the list.

Python support has recently been elevated to Beta, and mobile wheels are coming (https://github.com/slint-ui/slint/issues/4138#issuecomment-2910163153).

hyuri avatar May 26 '25 16:05 hyuri

@hyuri I've never heard of Slint before, but if they're providing iOS (and potentially Android) support, then sure - it makes sense that it is supported.

However, this is also something where Slint itself is in a position to provide the plugin - it doesn't need to be baked into Briefcase.

freakboy3742 avatar May 26 '25 21:05 freakboy3742

I've never heard of Slint before[...]

It's like a modern QML — founded by a former QT employee — written in Rust, that claims to be fully featured and lightweight, it has live preview that allows you to make changes to the GUI while the app is running, and they even offer a Figma exporter plugin.

Looks very promising and reasonably mature — I'm eyeing it for my next, more ambitious project that will require lots of custom widgets that don't need to be native — so, personally, I would even say it's more appealing to have support for it than the other frameworks listed in the original issue.

hyuri avatar May 27 '25 03:05 hyuri

I created a P4A (python-for-android) backend that handles Kivy on Android through Briefcase: https://github.com/pyCino/briefcase-p4a-backend

I made a Kivy plugin as well: https://github.com/pyCino/briefcase-kivy-bootstrap/

Disclaimer: Basic testing only. Your mileage may vary.

Hope it can be useful.

pyCino avatar Jul 02 '25 15:07 pyCino

Very impressive, thanks for the links.

mhsmith avatar Jul 03 '25 23:07 mhsmith

I made a Kivy plugin as well: https://github.com/pyCino/briefcase-kivy-bootstrap/

That's awesome - nice work!

One request, if I may - from a community management perspective, we'd like to keep the briefcase- prefix as an indicator that a package is "official" from the BeeWare project. If there are community-contributed projects/plugins, we want to encourage the use of the briefcasex- prefix.

Could I ask you to please rename the plugin (and PyPI project name) to briefcasex-kivy-bootstrap?

freakboy3742 avatar Jul 08 '25 00:07 freakboy3742

I created a P4A (python-for-android) backend that handles Kivy on Android through Briefcase: https://github.com/pyCino/briefcase-p4a-backend

By any chance, does this also mean we can now use plyer with Toga?

hyuri avatar Jul 08 '25 06:07 hyuri

By any chance, does this also mean we can now use plyer with Toga?

It might be possible - but I also wouldn't be surprised if it's not. Android is Java under the hood, and bridging between Java and Python requires some very complex plumbing. There is not, at present, any shared infrastructure in the Python ecosystem for how that plumbing works. Kivy has one implementation of that plumbing; Chaquopy (and thus BeeWare and Toga) has a different implementation. This plumbing will be very hard to make co-exist, because of how Java manages the bridging process (via JNI).

freakboy3742 avatar Jul 08 '25 06:07 freakboy3742

Done, the prefixes are all yours.

pyCino avatar Jul 08 '25 07:07 pyCino

Done, the prefixes are all yours.

Thanks... but I'm unclear what you've done here. It looks like you've deleted all your public repos (I can't find versions under the old or new names), and the PyPI package is still under the old name. Am I missing something?

freakboy3742 avatar Jul 08 '25 08:07 freakboy3742

@freakboy3742 I would like to take on this issue. I'm well versed in kivy framework.

kengoon avatar Jul 31 '25 16:07 kengoon

@kengoon We'd welcome any assistance you can provide. We're very interested in supporting Kivy - but don't have any particular knowledge or experience with Kivy as a framework.

freakboy3742 avatar Jul 31 '25 23:07 freakboy3742

@freakboy3742 alright. I will get to work. Happy to help.

kengoon avatar Aug 01 '25 06:08 kengoon

PyQt has been successfully deployed by some people to iOS: https://oforoshima.medium.com/compiling-ios-apps-with-pyqt6-c07082001f11

However not a bunch of details are given there... and they used PyQtDeploy -- note that PyQtdeploy is BSD which makes it trivial for us to reuse any deployment code in Briefcase.

johnzhou721 avatar Sep 01 '25 15:09 johnzhou721