Installing Kivy and Buildozer and building Android apps with Python 3.7 on Fedora 29

Kivy is a great UI framework for Python. You can use it to write cross-platform rich UI/UX applications for almost all platforms.

Kivy’s documentation is great, but there are no instructions for newer Fedora releases so it can be tricky to install it with Wayland, Python 3.7, dependencies etc.

So here is how to do it, it’s very simple:

We will need to compile stuff so install development tools:

sudo dnf groupinstall "Development Tools"

Now let’s install all the Kivy dependencies:

sudo dnf install gcc SDL2-devel zlibrary-devel mesa-libGL-devel "SDL2_*devel" ffmpeg gstreamer1-devel ccache ncurses-devel ncurses-devel.i686 libstdc++-devel.i686 gtk2-devel.i686 gtk2-devel pangox-compat-devel pangox-compat-devel.i686 idn2 unzip zlib-devel.i686 patch autoconf automake libtool ncurses-compat-libs ncurses-compat-libs.i686

Some of this may be unnecessary but it worked for me on several installations.

Let’s install Kivy now:

python3 -m venv venv # make a venv for kivy

pip install --upgrade pip # upgrade pip
pip install cython pillow
pip install git+https://github.com/kivy/kivy.git@master
pip install git+https://github.com/kivy/buildozer.git@master

This installs Kivy and buildozer build tool from their respective master branches.

Here is a simple Kivy app (thanks to this article) to verify it is working:

import kivy.app
import kivy.uix.boxlayout
import kivy.uix.textinput
import kivy.uix.label
import kivy.uix.button

class SimpleApp(kivy.app.App):
    def build(self):
        self.textInput = kivy.uix.textinput.TextInput()
        self.label = kivy.uix.label.Label(text="Your Message.")
        self.button = kivy.uix.button.Button(text="Click Me.")
        self.button.bind(on_press=self.displayMessage)
        self.boxLayout = kivy.uix.boxlayout.BoxLayout(orientation="vertical")
        self.boxLayout.add_widget(self.textInput)
        self.boxLayout.add_widget(self.label)
        self.boxLayout.add_widget(self.button)
        return self.boxLayout

    def displayMessage(self, btn):
        self.label.text = self.textInput.text

if __name__ == "__main__":
    simpleApp = SimpleApp()
    simpleApp.run()

Save this as main.py and run it with python main.py.

Works? Great! And now, let’s build for Android.

Initialize the project from the directory containing main.py with buildozer init. And build! buildozer -v android debug

Notice the -v. It is needed the first time as you need to agree with Android SDK and NDK license terms.

That’s it!

You can check my Android game built with Kivy here:

https://play.google.com/store/apps/details?id=nmilosev.tetten

Have fun!

 
11
Kudos
 
11
Kudos

Now read this

Chromium browser on Fedora ARM (23, LXDE) - Raspberry Pi 2

One of the few things missing from the official Fedora repositories is the Chromium browser. On an i686 or x86_64 system its pretty easy to find the correct Chromium build and install it. Sadly on ARM it seems like nobody is building it... Continue →