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 (updated Nov 2021):
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 idn2 unzip zlib-devel.i686 patch autoconf automake libtool ncurses-compat-libs ncurses-compat-libs.i686 perl-FindBin lld-devel python3-pyjnius
sudo dnf install pangox-compat --releasever=32 --repo=updated
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@2.0.0
pip install git+https://github.com/kivy/buildozer.git@1.2.0
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!