How to convert .py to APK file using Python for Android on Windows?

40,152

Solution 1

You can use VirtualBox Get it here and any Linux Distribution such as Ubuntu Ubuntu. After installing Ubuntu to your Virtualbox you can use below commands:

Run these commands on Terminal

sudo apt install git

sudo apt install python3-pip

git clone https://github.com/kivy/buildozer.git

cd buildozer

sudo python3 setup.py install

Now, navigate to your project directory using cd (or) goto your Project directory, RightClick -->select 'Open in terminal' and in Terminal type:

buildozer init 

Above Command creates a buildozer.spec file controlling your build configuration. You should edit it appropriately with your app name, file extensions used in the project, external dependencies etc. After configuring your buildozer.spec fille run below commands:

sudo apt update

sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev

pip3 install --user --upgrade Cython==0.29.19 virtualenv  # the --user should be removed if you do this in a venv

sudo pip3 install cython #(optional) If you got any Error as Cython not Found, use this

which buildozer

Above command is to check buildozer was added to your PATH), If no results found, add the following line at the end of your ~/.bashrc file--> export PATH=$PATH:~/.local/bin/

buildozer appclean

buildozer android debug

If you are asked for any licence agreement type y and click Enter

Once this process completes you will get a .apk file in your project directory bin/yourapp.apk

Solution 2

Kivy themselves used to have a virtual machine prepared with everything installed ready to go! For some reason they stopped, now you have to install the Virtual Machine yourself. You can see how to do this here

Share:
40,152
Manasa J
Author by

Manasa J

Updated on July 05, 2022

Comments

  • Manasa J
    Manasa J almost 2 years

    I am working on Kivy framework. I have some sample of Kivy which has .py extension which I want to convert to .apk files. I want to check whether these working on Android or not.

    I have some information about this. We have two ways to build an .apk file:

    1. Using Python for Android,
    2. Using Buildozer.

    But Buildozer is only supported on Linux. I thought it has some problems on Windows.

    Hence, I want to use Python for Android. But I have no idea how to approach this one.

    Have anyone tried this one.

    • razdi
      razdi about 5 years
      Have you tried reading the documentation? I see an example on the github page. Did you try that and face issues?
    • Manasa J
      Manasa J about 5 years
      can you share the examples on github
    • Abd El Kodous Souissi
      Abd El Kodous Souissi about 5 years
    • Vito Gentile
      Vito Gentile about 2 years
      Another option is to run Buildozer on Docker, which is a viable option even on Windows. I personally prefer this option, and here is a bit of information on how to do this.
  • Shm
    Shm about 4 years
    found some good youtube videos here