Android App using Python | Convert .Py to APK | #Kivy Tutorial

Updated: Sep 15

Hello readers, I expect you all know Python very well, now in this blog we are going to learn about how we can create Android App using Python using Kivy Framework. It's looking very exciting, so let's start.

Before starting we need to understand what is Kivy framework?

Kivy is a free and open-source Python framework for developing mobile apps and other multitouch application software with a natural user interface. It is distributed under the terms of the MIT License and can run on Android, iOS, Linux, macOS, and Windows. We can create Cross-Platform Applications using Kivy.


Requirements of the Project

  • Google Colab for generating APK from. Py / Linux

  • Any IDE (VSCode , Pycharm etc)

  • My ready-made colab notebook with commands [Python-to-APK]

Steps

  • Create Kivy GUI Application (Simple for example) in Local, It should run perfectly in the local system. For reference, you can clone my repository.

git clone https://github.com/Spidy20/Python_To_APK.git
  • Now go into the 'Python_To_APK' folder, We need to install the requirements of the project, open CMD in the directory and use the following command.

pip install -r requirements.txt
  • Now we need to run the simple application, code is already given by me, you can use that code. That code contains two parts, one is kivy code for GUI, and another one is backend code of Python.

  • You can directly run 'Window+Android_GUI.py' from that folder.


Let's understand the code.

  • The kivy code contains the GUI of our android app.

  • Python code will handle the backend.

Let's see the kivy code.

Now we need to merge that GUI code into python code, let's see the full code.

Let's run this code into windows, before converting it into APK.

python Window+Android_GUI.py

The output will be like this.




Now it's the most interesting part, we are going to convert Python(.py) to APK.

  • Use my colab, upload it into your colab file.

  • Don't try to change any lines of the colab notebook.

  • Now the main step is to rename your python file to 'main.py'

  • We need to upload our local python file into the runtime with necessary other files like images or other files which are needed by our python code.

  • We are using buildozer to create APK from a python file.

  • Buildozer Init command will generate the buildozer.spec file, we need to change some of the things in buildozer.spec file. (Refer to my tutorial, video link given below)

  • After running '!buildozer -v android debug' cell, it will take 25-30 minutes to generate the APK. It will be generated in the 'Bin' folder, download that apk, install it into your phone and see the result.


  • For more explanation of buildozer and changes see the full tutorial,

Now, let's install the APK into mobile and see how the application is looking into mobile.


  • Download APK into mobile, click on the install.

  • After the installation opens the application.

  • You can see the application is running fine on my android device(Samsung M51).



PS: Screenshots were captured from my youtube video.


See the full tutorial and code here.

Github

Thanks for reading, give a like to our blog.


Donation


Here we are just asking for the donations, if you want to donate us something then my UPI id and Paypal ID are mentioned below. We are creating quality content on youtube and making blogs for the same and publishing code openly. We are doing an open-source contribution.

UPI ID - kushalbhavsar58@ybl

Paypal - https://paypal.me/spidy1820

Wise - kushalbhavsar58@gmail.com


Note - We are just asking for donations.

Thanks & Regards

Machine Learning Hub