[HowTo] Install Kivy and Buildozer on Fedora 22 and Making APK

In a previous post, installing Kivy on Ubuntu 15.04 was issued. Today, there is a main development which is using SDL2 instead of Pygame. You can find why this is significant on Google.

I cannot find Kivy and Buildozer installion document for Fedora 22 and decided to write a recipe for it. So, lets get started. You will find 8 main sections for this topic:

  1. Installing Dependencies
  2. Creating Virtual Environment
  3. Installing Some Required Python Modules
  4. Installing Kivy
  5. Testing Kivy
  6. Installing Dependencies Required to Packaging for Android
  7. Configuring Buildozer
  8. Making APK File

Use these at your own risk.

Installing Dependencies

Firstly, with Fedora 22, a new package manager dnf is introduced. So I will use it as much as possible for future reference. You may find more detailed information about dnf here.

sudo dnf groupinstall "Development Tools" "Development Libraries"
sudo dnf install python-devel ffmpeg-libs SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel portmidi-devel libavdevice libavc1394-devel zlibrary-devel ccache java-1.8.0-openjdk java-1.8.0-openjdk-devel libstdc++-5.1.1-4.i686 zlib-1.2.8-7.i686 zlib-devel ncurses-libs-5.9-18.20150214.i686

Note that there may much more than you need to run Kivy. I did not make a separated list by selecting only necessaries.

Creating Virtual Environment

There are many reasons which are out of scope why you are suggested to continue this recipe on a virtual environment. Basically, you may wish to use different versions of different modules and continuously re-installing the relevant versions may become a pain.

virtualenv --no-site-packages kivyInstall


Installing Some Required Python Modules

Cython version is a crucial point here. For kivy 1.9.0, Cython version up to 0.21.2 is supported as stated in documentation. You are suggested to check the proper Cython version from this link at the time you are applying these instructions.

kivyInstall/bin/pip install Cython==0.21.2
kivyInstall/bin/pip install git+https://github.com/kivy/buildozer.git@master
kivyInstall/bin/pip install git+https://github.com/kivy/plyer.git@master
kivyInstall/bin/pip install -U pygments docutils
kivyInstall/bin/pip install markupsafe


Installing Kivy

Now we can install Kivy Framework by typing:

kivyInstall/bin/pip install kivy

This may require some time to complete, be patient. If any error occurs, firstly check the Cython version and try to search the error.

Testing Kivy

After installation is complete, you can test your Kivy installation with the simple button code from Kivy homepage:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text='Hello World')


In order to run this code, put it on a file and follow these:

cd ~
. kivyinstall/bin/activate
python codeToRun.py

The cd command parameter may change if you have installed your virtual environment to a place other than your home directory.

After this, you should see a button doing nothing on a window.

Installing Dependencies Required to Packaging for Android

Most of dependencies have been installed at the first stage. There are some dependencies which should be installed by your virtual environments pip:

kivyInstall/bin/pip install git+https://github.com/kivy/buildozer.git@master
kivyInstall/bin/pip install git+https://github.com/kivy/plyer.git@master
kivyInstall/bin/pip install -U pygments docutils
kivyInstall/bin/pip install markupsafe

Here, plyer is not a mandatory but I added it to list since it may necessary for many cases.

Any suggestions/corrections are welcomed. Feel free to post them.

Configuring Buildozer

Firstly, make a folder and put the basic button example code on it with the name main.py.

cd ~
mkdir codeToCompile
cat >> main.py
buildozer init

After pasting code at the third command, end cat command with CTRL+D. Last command initializes buildozer and there will be a buildozer.spec file which we can make a lot of configurations about our app or compilation options.

Before the compilation begins, there is one necessary and one suggested configuration will be made at buildozer. In buildozer.spec file:

For this example, a version does not exist in Python file, so manual version method will be used. Make versioning part it look like this:

# (str) Application versioning (method 1)
#version.regex = __version__ = ['"](.*)['"]
#version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 1.2.0

After this, we want to see if there is an error when compiling code. In this case, we can open debug output. Make log_level part as follows:


# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

Making APK File

The last part is generating an APK file for Android devices. This will probably be the most time-consuming process (for the first time, after the first time it will be very quickly).

buildozer android debug

At first time, Buildozer will install necessary components for building an APK file. Sequentially, it will generate an APK file in bin in the folder when main.py exist.

You can also install the app to your phone and run it directly on buildozer. The following command generates an apk file, sends and installs it to phone and runs the application:

buildozer android debug deploy run

That is the end of this recipe. Please do not hesitate to contact me for any suggestions or corrections.

comments powered by Disqus