If you are a Windows/Mac developer using Kivy to build an Android app you will need to use Linux or a Linux VM to build a distribution.
Download and install VirtualBox. If you have never used Linux before I recommend an Ubuntu-type. I created a Lubuntu 64-bit VM. There is a known screen resolution issue with Lubuntu. During installation several screens will have the confirm buttons off-screen. Hit enter to proceed through those prompts.
Don’t be stingy with the HD allocation. If you underestimate and need to allocate additional space, try this method.
As a Windows 8.1 user I found myself unable to build 64-bit VMs. There are two likely solutions for an Intel processor. Either Hyper-V needs to be disabled (Programs and Features) or VT-x needs to be enabled. You can find VT-x under UEFI firmware or BIOS. Mine was under BIOS, under an option called Intel Virtualization Tech.
If you developed your app in Windows you’ll need to share those files with the VM. In VirtualBox you’ll be using Guest Additions. The .iso may have been included with your VB download or you may be prompted to download when you change the needed settings.
On the host computer, enter the following on the command line in the VirtualMachine directory, modifying the shared folder path as needed:
In the VirtualMachine Application Window toolbar, click Devices > Insert Guest Additions CD Images…
On the guest computer, enter the following on the command line:
Be advised some programs cannot modify files in a shared folder.
The documentation recommends using Buildozer, which is designed to simplify the distribution process. Buildozer has numerous dependencies. If you’re using a Ubuntu variant you will already have Python 2.7 on your VM.
You will also need 32-bit libraries. If you debug without them, Buildozer will refer you to the documentation, which lists the cmd for Ubuntu.
I was also asked to install several additional Python modules:
Install and upgrade Buildozer, then initialize it in your app’s directory.
Buildozer will generate a .spec file that needs to be updated with your app information. Go ahead and set the log_level to 2.
One issue of note: To avoid a bug, consider setting requirements = kivy,python2 to avoid a pythonhost context attribute error if using the android_new command. If using the android command, use python.
Run debug and buildozer will prompt you to install any missing libraries. Buildozer will install Apache ANT, the Android SDK, and the Android NDK for you. This will take a few minutes.
If all is well, you can deploy and run your app like so:
At some point, Buildozer may throw an error and ask you to raise the log_level in your .spec to 2. Consider:
For some problems you will need to debug, which involves attaching your Android device to USB and accessing it through the VM. The Android SDK has the build-in debugging tool ADB logcat, which lives under platform-tools if it has been installed, and there is also a version included with Buildozer.
On your Android device you will need to enable USB Debugging, which may require a special handshake unique to your device (I’m actually not joking, they hide it from the n00bz) so you’ll need to search for how to find it on your device.
VirtualBox users will need to download and install the VirtualBox extension pack. I ran into several issues attempting to enable USB for a Lubuntu VM. One, I did not have a vboxusers group. Two, when I finally did get everything set up Lubuntu knew the device was there but would not list it as a connected device. USB does appear to be somewhat finicky in VirtualBox.
Once your device is available, you can run things like this. I was able to build my working distribution with the latter.
The documentation also recommends using the Kivy VM, which is a pre-built image provided by the Kivy team. Kivy VM appears to be out of date. Buildozer generated a distribution error that I could not resolve by updating. When I researched the issue I was referred back to manually installing Python-for-Android.
I recommend that you attempt to use Buildozer before attempting to use p4a directly. I found manually installing Android SDK/NDK to be time-consuming and confusing. I have not yet built a test app with this method, but I will document how I got to the point where I could attempt a distribution.
For the Android SDK and NDK, I used this guide, paraphrased below. Download and extract the Android SDK command line tools (not the Studio IDE). I unzipped the SDK in my Downloads directory. Go to the tools subdirectory in the terminal.
Click “Install # Packages.” You will also need to install the API for your target machine if you’re not using the latest version (in my case, this was 25). I found that the NDK, which we’ll discuss in a minute, only went to 24, so I had to install 24 of the SDK as well. See What is the API level? for an explanation and the Developer Dashboard for information on which devices use which APIs. You may encounter installation issues. Try deleting the folder and extracting it again. Don’t forget to empty your trash.
Download and extract the Android NDK. You will need to make sure you have the correct target API under /platforms. (As stated above, I found NDK didn’t have API 25.)
Now you should be able to run p4a. p4a generates good error messages, so hopefully if you’re missing something you’ll be able to figure out what you need. The command I worked with was:
I was told by p4a that I needed to use the command –arch=armeabi-v7a, YMMV.