[Tutorial] Android development with Python and Kivy - Introduction


In this post I’ll show you how to start with mobile development using Python and Kivy. You will see how to download and configure Kivy, and we will create a Hello World to test it. And finally, we will build our application to an APK, and install it on Android.

I - Installation

Kivy for Android Virtual Machine

If you are going to develop for Android, you must to be using Linux and a lot of dependence are necessary. So it’s not recommend to install everything, it can be hard and may not work perfectly.

To turn our development easier, Kivy provide us a Virtual Machine ready for use!! Yep, you just need to download it and use. Download it from here: http://kivy.org/#download

Scroll to the end of screen, and you will see the download link.

Downloading Kivy VM

Each platform has a different installation process, so I recommend you to download and install the virtual machine to avoid problems. You can run the VM(based on Ubuntu 32 bits) using Oracle Virtual Box.

Start your VM and let’s create our first project!!

II - Creating our first project

From now, we will create a simple project to test if everything is fine. You can run this source in your computer. After we finish it, we can build for Android.

from kivy.app import App
from kivy.uix.button import Button

class Hello(App):
  def build(self):
    btn = Button(text='Hello World')
    return btn


This code will create a simple window, and a button with the text “Hello World”.

Simple Kivy Window

III - Build Python for Android

Now, let’s build our hello world to Android. (The main file of you project must be named as main.py)

To create an Android project with Python and Kivy, open you terminal and run:

$ git clone git://github.com/kivy/python-for-android
$ cd python-for-android

The command above will download the necessary tools to start the development. Now, you need to build the modules that you will use in your project. In that case, we are using only Kivy. So, run:

% ./distribute.sh -m "kivy"

It will download and configure everything that you need.

Now, go to the dist/default folder and run:

./build.py  --dir <path to your app
            --name "<title>"
            --package <org.of.your.app>
            --version <human version>
            --icon <path to an icon to use>
            --orientation <landscape|portrait>
            --permission <android permission like VIBRATE> (multiple allowed)
              <debug|release> <installd|installr|...>

For example, in my case, I will run:

./build.py  --dir /tmp/
            --name "Hello"
            --package com.rhesoft
            debug installd

This command will build the Apk. The apk will be created at bin folder. Get it and install in your device.

App running on my device:

Kivy on Android Hello World

That’s it!! Now, you are able to develop using Python + Kivy for Android. This blog has more tutorials about it, take a look :)

Thanks for reading, if you need something, just comment here!!

Aron Bordin

Aron Bordin
Computer Science Student and AI researcher. Always coding something fun :)

[Tutorial] Developing Android Background Services

### Welcome!In this post, I'll show you how to develop background services on Android Studio. We'll see two type of services: `Service` a...… Continue reading