From Python to APK: How to use Kivy and Buildozer on Windows
Kivy and Buildozer together allow developers to create an Android application package (APK) from Python code. While working on a project with these libraries it has come to my attention that this process can however be troublesome and time-consuming. To spare others the hours of looking at rushed documentation (especially for Buildozer) I decided to merge some guides together of all the extra work that to be done to be able to make Buildozer compile your Python code on a Windows operating system.
Virtual Machine containing Kivy and Buildozer setup
- Download Kivy Buildozer VM and unzip the file.
- Download the version of VirtualBox for your machine from Oracle VirtualBox download area and install it.
- Download Oracle VM VirtualBox Extension Pack for all platforms and install it.
- Start VirtualBox, click on File » Import Appliance…
- Select the extracted directory, file named, Buildozer VM.ovf
- Click on Settings » General » Advanced and select Bidirectional in the drop-down list for Shared Clipboard:, and Drag’n’Drop:
- Click on Settings » Shared Folders and click Add new shared folder. e.g. Kivy Apps folder. Make sure Auto-mount has been selected.
- Click on Settings » USB, check Enable USB Controller, checkbox USB 2.0 (EHCI) Controller, and click Add new USB filters e.g. Samsung phone.
PyCharm IDE Setup
- Download PyCharm Community and install it.
- Install KV Lang Auto-completion and Highlighting
- Please refer to PyCharm Project Interpreter Setup
Setting up adb/USB drivers on your Virtual Machine
- Start VirtualBox, select Kivy/Buildozer VM and click Start
- Password is kivy
- Start your file manager on your Virtual Machine and Click on View » Show Hidden Files
- Navigate to /home/kivy/ and open .bashrc
- Add the following lines to the end of the file: export PATH=${PATH}:~/.buildozer/android/platform/android-sdk/tools export PATH=${PATH}:~/.buildozer/android/platform/android-sdk/platform-tools
- Navigate to /etc/udev/rules.d/ and open a terminal here by right clicking and selecting Open Terminal here
- Enter sudo mousepad 80-android.rules into the terminal
- Add the following line to the file SUBSYSTEM==”usb”, ATTR{idVendor}==”USB-VENDOR-ID”, MODE=”0666″ In which you replace USB-VENDOR-ID with the ID of your device in Table 1
- Give permission to all users to read and write by typing chmod 777 80-android.rules into the terminal
- Enter adb devices into the terminal to start detecting your phone or tablet
Create a package for Android
- Start VirtualBox, select Kivy/Buildozer VM and click Start
- Password is kivy
- Copy your Kivy App from local machine to a folder in Home folder.
- Double click Home folder
- Double click your Kivy App folder
- Right mouse click and select Open Terminal here
- At Terminal command prompt, type buildozer init to create buildozer.spec file.
- Double click buildozer.spec file to make changes (e.g. title, package.name, log_level = 2) and save changes.
- At Terminal command prompt, type buildozer android debug deploy run
- Wait a few minutes and you should be done!