kivy
  1. kivy-packaging-kivyapps

Packaging Kivy Apps - Deploying Kivy Applications

Introduction

Kivy is a cross-platform framework that allows developing applications for desktop and mobile users with the same codebase. Packaging Kivy apps involves creating an executable file and a package installer.

In this tutorial, we will learn how to package Kivy applications for desktop and mobile users.

Installing Tools

Before we proceed to package Kivy apps, we need to have the following tools installed:

  • Python - Version 2.7.14 or 3.4 or newer
  • Kivy - Version 1.11.1 or newer
  • Buildozer - A Python-based virtual machine for building Android applications

Packaging Kivy apps for Desktop

To package Kivy apps for Desktop, follow the below steps:

Step 1: Create a Setup File

We need to create a setup file for the desktop user. This file will contain the necessary information regarding the app such as app name, version number, author, and description, etc.

from setuptools import setup

setup(
    name='myapp',
    version='0.1',
    packages=['myapp'],
    url='',
    author='Your Name',
    author_email='',
    install_requires=[
        'kivy',
        'pywin32;platform_system=="Windows"'
    ],
)

Step 2: Create a Distribution Package

We will create a distribution package using the below command:

python setup.py sdist

Step 3: Install the Distribution Package

After the distribution package is created, we can install it using the below command:

python setup.py install

Step 4: Create an Executable File

Next, we need to create an executable file using the below command:

python -m PyInstaller myapp.py

Step 5: Package the App

Finally, we can package our app by creating an installer using NSIS or Inno Setup, or we can use auto-py-to-exe package for packaging.

pip install auto-py-to-exe

Packaging Kivy apps for Mobile

To package Kivy apps for Mobile, we can use the Buildozer tool. Follow the below steps:

Step 1: Install Buildozer

Use the below command to install Buildozer:

pip install buildozer

Step 2: Create a Buildozer Spec File

Next, we need to create a buildozer.spec file that contains the configuration settings like app name, version, orientation, permissions, and more.

[app]
title = My App
package.name = myapp
package.domain = org.test
source.dir = .

version = 0.1

requirements = kivy

orientation = portrait

[buildozer]
log_level = 2
warn_on_root = 1

# Android-specific
android.sdk = 21
android.ndk = 17b
android.sdk_path = /home/user/.buildozer/android/platform/android-sdk
android.ndk_path = /home/user/.buildozer/android/platform/android-ndk-r17b
android.api = 27
android.minapi = 24
android.gradle_version = 4.4

Step 3: Build the App

We can build the app using the below command:

buildozer android debug

Once the build process is complete, we will get an APK file in the bin folder.

Conclusion

By following the above steps, we can package our Kivy app for desktop and mobile users. It is essential to remove unnecessary files and dependencies before packaging to reduce the app size and for security purposes. With packaging, we can distribute our applications to target users, which is an essential part of the app development process.

Published on: