From Python to APK: How to use Kivy and Buildozer on Windows

2 minute read

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

  1. Download Kivy Buildozer VM and unzip the file.
  2. Download the version of VirtualBox for your machine from Oracle VirtualBox download area and install it.
  3. Download Oracle VM VirtualBox Extension Pack for all platforms and install it.
  4. Start VirtualBox, click on File » Import Appliance…
  5. Select the extracted directory, file named, Buildozer VM.ovf
  6. Click on Settings » General » Advanced and select Bidirectional in the drop-down list for Shared Clipboard:, and Drag’n’Drop:
  7. Click on Settings » Shared Folders and click Add new shared folder. e.g. Kivy Apps folder. Make sure Auto-mount has been selected.
  8. 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

  1. Download PyCharm Community and install it.
  2. Install KV Lang Auto-completion and Highlighting
  3. Please refer to PyCharm Project Interpreter Setup

Setting up adb/USB drivers on your Virtual Machine

  1. Start VirtualBox, select Kivy/Buildozer VM and click Start
  2. Password is kivy
  3. Start your file manager on your Virtual Machine and Click on View » Show Hidden Files
  4. Navigate to /home/kivy/ and open .bashrc
  5. 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
  6. Navigate to /etc/udev/rules.d/ and open a terminal here by right clicking and selecting Open Terminal here
  7. Enter sudo mousepad 80-android.rules into the terminal
  8. 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
  9. Give permission to all users to read and write by typing chmod 777 80-android.rules into the terminal
  10. Enter adb devices into the terminal to start detecting your phone or tablet

Create a package for Android

  1. Start VirtualBox, select Kivy/Buildozer VM and click Start
  2. Password is kivy
  3. Copy your Kivy App from local machine to a folder in Home folder.
  4. Double click Home folder
  5. Double click your Kivy App folder
  6. Right mouse click and select Open Terminal here
  7. At Terminal command prompt, type buildozer init to create buildozer.spec file.
  8. Double click buildozer.spec file to make changes (e.g. title, package.name, log_level = 2) and save changes.
  9. At Terminal command prompt, type buildozer android debug deploy run
  10. Wait a few minutes and you should be done!