Working On Android

Sat Nov 11, 2023Listen to this post

Or, more realistically, "Working Cross Platform", except that the only two platforms I selfishly care about are Android and Debian-descended Linux. Last time I touched Android in anger, I was working on a MacOS machine, and trying to do it in JavaScript. This was after failing to get cljs up and running. Given that my current explorations are, by virtue of HuggingFace, going through Python, I figured it might be a good idea to try that as a mobile development language.

It turns out it's not complete trash?

There's two realistic options here; beeware/briefcase and kivy/buildozer. The TLDR here is

Beeware

The tutorial is a great place to start with this one. It gets you through building a custom trivial app, building it, and running it on an android emulator. It also feels like subsequent builds of the application are much faster than the initial one. If you have a simple application, that happens to fit within Toga's constraints, you should absolutely use this, because deploying things is ridiculously easy. I had a basic app up and running on an emulator inside of like twenty minutes, and had it running on my literal phone about twenty minutes after that.

The trouble is that if you want to do things like have clickable images, this is not the app for you. That link, which I posted twice in this post so far, links to a multi-page discussion from January of 2020 in which BrendanSimon valiantly tries to convince the Beeware guys that a real cross-platform GUI widget system needs to let people click/tap/whatever on things which aren't always 100% button-shaped, and which sometimes have (gasp) icons instead of or in addition to text. In case you were wondering, the issue is still open, but the framework developers seem ambivalent whether anyone really needs this.

Which, given that I want to do professional-grade work here, rules me out. Check it out for toys, in case you want to test the waters of personal android development, or if packaging your project as a .deb is more important to you than running it on your phone.

I'm moving along.

Kivy

buildozer is rough. It has documentation, and it technically tells you how to install it. However, after hours of trying to get it work directly, and scraping through their github and StackOverflow questions trying to figure out why my builds were failing with SSL errors, and unsuccessfully asking for help on their Discord, what I found out is that those installation instructions are incorrect. They tell you to do pip3 install --user --upgrade buildozer, but that'll install it in some weird semi-coherent way where certifi doesn't have valid SSL certificates hooked into it correctly. What I actually had to do instead was python3 -m pip install --user --upgrade buildozer. I'm guessing this is because Ubuntu 22.04 ships with multiple versions of Python3? I'm not sure what the underlying implications here are, but the above worked for me.

Once you get installation headaches out of the way, the Kivy tutorials are also pretty self-explanatory. Unlike beeware, they have an extremely general widget model that lets you do things like specify tappable/swipeable images and do all the mobile app things you're used to. They've even got a separate, even-more-mobile-focused toolkit named KivyMD which I might look at if I hit any walls in terms of UI responsiveness. Also unlike beeware, they seem to have a YAML-based specification language for their UI components? Honestly, this seems pretty insane, but from what I've seen, you can easily build your own object trees inside of .py files without bothering with .kvs at all. Which is exactly what I intend to do, but your mileage may vary.

I haven't done any serious work with either of these frameworks yet, but I have done the basic hello world in both. And I've got a few projects kicking around my head that I think could benefit from being implemented as desktop/mobile apps which this exploration is getting me closer to actually implementing.

As always, I'll let you know how it goes.


Creative Commons License

all articles at langnostic are licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License

Reprint, rehost and distribute freely (even for profit), but attribute the work and allow your readers the same freedoms. Here's a license widget you can use.

The menu background image is Jewel Wash, taken from Dan Zen's flickr stream and released under a CC-BY license