Building and deploying a Kivy Python app to Android using Buildozer is a relatively straightforward process once you have all the necessary tools installed. In this tutorial, we will walk you through the steps to build and deploy a Kivy Python app as an .apk file on both Windows and Linux operating systems.
Prerequisites:
Before we begin, make sure you have the following prerequisites installed on your system:
- Python (version 3.6 or later recommended)
- Pip (Python package installer)
- Virtualenv (Python virtual environment)
- Buildozer (Python package for packaging and deploying Python apps)
- Android SDK
- Java Development Kit (JDK)
Step 1: Install Buildozer
First, you need to install Buildozer on your system. You can do this by running the following pip command:
pip install buildozer
Step 2: Create a Kivy Python App
Next, create a Kivy Python app that you want to build and deploy to Android. You can write your app code in a file named main.py. Here is a simple Kivy Python app code that you can use as an example:
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello, World!')
TestApp().run()
Step 3: Create a Buildozer.spec File
Create a Buildozer.spec file in the same directory as your main.py file. This file contains configuration settings for Buildozer. Here is an example of a Buildozer.spec file:
[app]
title = My Kivy App
package.name = mykivyapp
package.domain = org.test
source.dir = .
requirements = python3,kivy
orientation = portrait
fullscreen = 0
[buildozer]
log_level = 2
warn_on_root = 1
Step 4: Build and Deploy the App
Now, navigate to the directory where your main.py and Buildozer.spec files are located and run the following command to build the .apk file:
buildozer -v android debug
This command will start the build process and create an .apk file in the bin directory of your project directory.
Step 5: Deploy the App to Android Device
You can now deploy the built .apk file to your Android device for testing. Connect your Android device to your computer and run the following command to install the .apk file on your device:
buildozer android deploy run
This command will install the .apk file on your connected Android device and launch the app automatically.
Conclusion:
In this tutorial, we have shown you how to build and deploy a Kivy Python app as an .apk file to Android using Buildozer on both Windows and Linux operating systems. By following these steps, you can easily create and test your Kivy Python apps on Android devices. Happy coding!
Hey folks 🙂 You can find the most important commands in the description. I also want to mention this tutorial works perfectly fine for Ubuntu.
Hi please help! Everything works well til command in Ubuntu: adb connect YOUR_IP:5555. the error message is: failed to connect to 'myIP:5555': Connection timed out. Even in cmd i got the same massage like your: restarting in TCP mode port: 5555. All your steps with setting phones I checked. Do you have for me some suggestion?
Cython 3.0.11 is not compatible with buildozer, so instead of "sudo pip3 install –upgrade cython" I suggest "sudo pip3 install cython==0.29.37' to avoid possible compatibility errors.
Its error how to fix it
# Check that aidl can be executed
# Search for Aidl
# Run '/home/kali/.buildozer/android/platform/android-sdk/build-tools/35.0.0/aidl'
# Cwd None
Traceback (most recent call last):
File "/usr/local/bin/buildozer", line 8, in <module>
sys.exit(main())
^^^^^^
File "/usr/local/lib/python3.11/dist-packages/buildozer/scripts/client.py", line 13, in main
Buildozer().run_command(sys.argv[1:])
File "/usr/local/lib/python3.11/dist-packages/buildozer/__init__.py", line 1024, in run_command
self.target.run_commands(args)
File "/usr/local/lib/python3.11/dist-packages/buildozer/target.py", line 93, in run_commands
func(args)
File "/usr/local/lib/python3.11/dist-packages/buildozer/target.py", line 103, in cmd_debug
self.buildozer.prepare_for_build()
File "/usr/local/lib/python3.11/dist-packages/buildozer/__init__.py", line 172, in prepare_for_build
self.target.install_platform()
File "/usr/local/lib/python3.11/dist-packages/buildozer/targets/android.py", line 616, in install_platform
self._install_android_packages()
File "/usr/local/lib/python3.11/dist-packages/buildozer/targets/android.py", line 567, in _install_android_packages
self._check_aidl(installed_v_build_tools)
File "/usr/local/lib/python3.11/dist-packages/buildozer/targets/android.py", line 592, in _check_aidl
_, _, returncode = self.buildozer.cmd(aidl_cmd,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/buildozer/__init__.py", line 289, in cmd
process = Popen(command, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 1026, in _init_
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.11/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/kali/.buildozer/android/platform/android-sdk/build-tools/35.0.0/aidl'
┌──(kali㉿localhost)-[~/pacman]
└─$
a fantastic video. hats off
sorry if this may stupid so should i install all these required libraries into the cloned buildozer folder
Hi! I am trying to build a simple program but kept on encountering this error. Any idea how tp fix this? Thanks!
[WARNING]: ERROR: /mnt/c/Users/Public/PYTHON/main/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/dists/myapp/gradlew failed!
No setup.py/pyproject.toml used, copying full private data into .apk.
Applying Java source code patches…
Applying patch: src/patches/SDLActivity.java.patch
# Command failed: ('/usr/bin/python3', '-m', 'pythonforandroid.toolchain', 'apk', '–bootstrap', 'sdl2', '–dist_name', 'myapp', '–name', 'My Application', '–version', '0.1', '–package', 'org.test.myapp', '–minsdk', '21', '–ndk-api', '21', '–private', '/mnt/c/Users/Public/PYTHON/main/.buildozer/android/app', '–android-entrypoint', 'org.kivy.android.PythonActivity', '–android-apptheme', '@android:style/Theme.NoTitleBar', '–orientation', 'portrait', '–window', '–enable-androidx', '–copy-libs', '–arch', 'arm64-v8a', '–arch', 'armeabi-v7a', '–color=always', '–storage-dir=/mnt/c/Users/Public/PYTHON/main/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a', '–ndk-api=21', '–ignore-setup-py', '–debug')
thank you very much. u save my life
adb logcat | grep "python"
Worked for me probably cuz of different version of adb.
after finishing it fails with an error and
says, packaging has no attribute version…
what does this mean?
linux aint installing
Excellent tutorial, I managed to make it work. I ran into a ton of problems but managed to google and use chatgpt for solutions. If you get a failure with gradle, it worked when i switched to java vers 17. Also upgrade to WSL2 to avoid error: C compiler cannot create executables.
Vielen Dank!!! Du bist ein life saver
How can i deploy my app if I'm using windows? is it necessary to use linux
I dont understrand anything, why is there suddenly a .sepc and buildozer folder in the github project, last time these two folders did not exist
Nice tutorial! Just one little thing: in order to make this work, WSL needs to be upgraded from WSL1 to WSL2, otherwise you get 'C compiler cannot create executables' error
Thanks Bro 💪
I wish I could like this video twice.
Wonderful! Thank you so much!
that worked well ! too bad we can't use buildozer directly from cmd and that WSL can't access USB easily. Before watching this video I tried to hack around with WSL by redirecting adb to the cmd one with a symbolic link. It failed miserably but connected through tcpip did the job in the end.