[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:
- Installing Dependencies
- Creating Virtual Environment
- Installing Some Required Python Modules
- Installing Kivy
- Testing Kivy
- Installing Dependencies Required to Packaging for Android
- Configuring Buildozer
- Making APK File
Use these at your own risk.
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.
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.
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.
Now we can install Kivy Framework by typing:
This may require some time to complete, be patient. If any error occurs, firstly check the Cython version and try to search the error.
After installation is complete, you can test your Kivy installation with the simple button code from Kivy homepage:
In order to run this code, put it on a file and follow these:
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:
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.
Firstly, make a folder and put the basic button example code on it with the name main.py.
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:
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:
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).
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:
That is the end of this recipe. Please do not hesitate to contact me for any suggestions or corrections.