174

I would like to develop a (rather simple) android app to be distributed via Play Store. I would like to do so completely in python. However, the online research hasn't quite enlightened me: most comments are either outdated (>1 year old, and I feel there might be better integration of python since then) or they talk about running python in android (e.g. here).

Therefore, I'm looking for information regarding the questions:

  • is it feasible to develop an App completely in python - and what are the tools to do so? (Is e.g. Kivy recommendable?)
  • if so: what are the best software environments to implement this? (I unsuccessfully tried using Android Studio but couldn't figure out a way to run python code there.)

I'm quite new to app development and would highly appreciate any leads of doing this in python rather than in Jave etc., which I don't know yet.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
Ivo
  • 3,890
  • 5
  • 22
  • 53
  • 1
    in the past, i used kivy and their buildozer program. they have documentation here https://kivy.org/docs/guide/packaging-android.html – e.s. May 24 '18 at 15:37
  • Natively you have to use either Java or Kotlin, however as others have pointed out there are 3rd party "app-builders" or frameworks you can use with python like PyMob or Kivy. – Dominik Schmidt May 29 '18 at 17:30
  • 14
    I created an Android game that is completely developed in Python using Kivy. It is called CoinTex available here at Google Play: https://play.google.com/store/apps/details?id=coin.tex.cointexreactfast. The source code of the game is available here at GitHub: https://github.com/ahmedfgad/CoinTex. I also wrote a book that will be published thus year for building Android apps using Python. It is titled "Building Android Apps in Python Using Kivy with Android Studio: With Pyjnius, Plyer, and Buildozer Ahmed Fawzy Gad" available here at Amazon: https://www.amazon.com/dp/1484250303. – Ahmed Gad Jul 23 '19 at 00:56
  • 2
    Can't post an answer, but [here seems to be a solution](https://www.pycon.it/conference/talks/developing-android-apps-completely-in-python): *Different technologies will be demonstrated, including PySide-based QML GUIs using the Necessitas Qt port and the Py4A/SL4A-based approach, which can be combined with Android’s WebKit and re-use Python web frameworks.* – Basj Oct 30 '19 at 08:18
  • 9
    I do not understand why this question was closed. It should imho be reopened. – cknoll Oct 14 '20 at 09:32

4 Answers4

174

To answer your first question: yes it is feasible to develop an android application in pure python, in order to achieve this I suggest you use BeeWare, which is just a suite of python tools, that work together very well and they enable you to develop platform native applications in python.

checkout this video by the creator of BeeWare that perfectly explains and demonstrates it's application

How it works

Android's preferred language of implementation is Java - so if you want to write an Android application in Python, you need to have a way to run your Python code on a Java Virtual Machine. This is what VOC does. VOC is a transpiler - it takes Python source code, compiles it to CPython Bytecode, and then transpiles that bytecode into Java-compatible bytecode. The end result is that your Python source code files are compiled directly to a Java .class file, which can be packaged into an Android application.

VOC also allows you to access native Java objects as if they were Python objects, implement Java interfaces with Python classes, and subclass Java classes with Python classes. Using this, you can write an Android application directly against the native Android APIs.

Once you've written your native Android application, you can use Briefcase to package your Python code as an Android application.

Briefcase is a tool for converting a Python project into a standalone native application. You can package projects for:

  • Mac
  • Windows
  • Linux
  • iPhone/iPad
  • Android
  • AppleTV
  • tvOS.

You can check This native Android Tic Tac Toe app written in Python, using the BeeWare suite. on GitHub

in addition to the BeeWare tools, you'll need to have a JDK and Android SDK installed to test run your application.

and to answer your second question: a good environment can be anything you are comfortable with be it a text editor and a command line, or an IDE, if you're looking for a good python IDE I would suggest you try Pycharm, it has a community edition which is free, and it has a similar environment as android studio, due to to the fact that were made by the same company.

I hope this has been helpful

maroof shittu
  • 2,027
  • 1
  • 11
  • 14
  • 5
    Is it just me, or has VOC been abandoned? – Nic Nov 22 '18 at 07:18
  • 3
    this is a dead end (Last time I checked it out: Dec. 2018). One or more components in this overly complex solution isn't functioning anymore, or can't keep itself up to date. – Berry Tsakala Mar 06 '19 at 11:39
  • 4
    Just an update to this for 2019, but Kotlin is now the preferred language for Android development. – DaveTheMinion Jul 04 '19 at 20:57
  • @BerryTsakala can you elaborate? So do you think BeeWare solutions will be dead in a near future (I want to avoid investing time on it, then...)? – Basj Oct 26 '19 at 21:25
  • 4
    @Basj I'd like to say that Beeware will definitely be around for a while, because just by taking a look at its GitHub account you will find that it is being actively developed, and if you head over to the Gitter channel, you can always reach the whole team, especially Dr Russell (freakyboy) the creator, and the community is quite friendly, and also there was a very recent tweet (Sep 26 2019) tweet from their official account announcing that they received an education grant from the Python software foundation. I think it would be worth your time, especially if you like python as a language – maroof shittu Oct 27 '19 at 20:19
  • 2
    BeeWare does not seem to support Android (Java) at this stage in any event. – Mark Anderson Feb 16 '20 at 03:46
  • but beeware does not support image and other widgets – Search Imtiyaz Jan 07 '21 at 13:41
  • 2
    hi @SearchImtiyaz from toga documentation you can use [ImageView](https://toga.readthedocs.io/en/latest/reference/api/widgets/imageview.html) you can also check out the full [Toga Reference](https://toga.readthedocs.io/en/latest/reference/api/index.html) for list of available widgets – maroof shittu Jan 12 '21 at 03:32
20

You could try BeeWare - as described on their website:

Write your apps in Python and release them on iOS, Android, Windows, MacOS, Linux, Web, and tvOS using rich, native user interfaces. One codebase. Multiple apps.

Gives you want you want now to write Android Apps in Python, plus has the advantage that you won't need to learn yet another framework in future if you end up also wanting to do something on one of the other listed platforms.

Here's the Tutorial for Android Apps.

emmagordon
  • 1,222
  • 8
  • 17
18

Android, Python !

When I saw these two keywords together in your question, Kivy is the one which came to my mind first.

Kivy logo

Before coming to native Android development in Java using Android Studio, I had tried Kivy. It just awesome. Here are a few advantage I could find out.


Simple to use

With a python basics, you won't have trouble learning it.


Good community

It's well documented and has a great, active community.


Cross platform.

You can develop thing for Android, iOS, Windows, Linux and even Raspberry Pi with this single framework. Open source.


It is a free software

At least few of it's (Cross platform) competitors want you to pay a fee if you want a commercial license.


Accelerated graphics support

Kivy's graphics engine build over OpenGL ES 2 makes it suitable for softwares which require fast graphics rendering such as games.



Now coming into the next part of question, you can't use Android Studio IDE for Kivy. Here is a detailed guide for setting up the development environment.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
  • 6
    Windows support is lagging way behind production standards (or even hobbyist standard). Plus, half of the world can't use it due to lack for RTL support. – Berry Tsakala Mar 06 '19 at 11:42
  • 2
    Why did you leave Kivy and change it to native development tools? You suggests that it has some disadvantages. – igoemon Jan 24 '20 at 07:32
  • 1
    Plus Google Collab with these settings: https://towardsdatascience.com/3-ways-to-convert-python-app-into-apk-77f4c9cd55af. It's fast, easy and great! – KBill May 23 '22 at 11:23
17

There are two primary contenders for python apps on Android

Chaquopy

https://chaquo.com/chaquopy/

This integrates with the Android build system, it provides a Python API for all android features. To quote the site "The complete Android API and user interface toolkit are directly at your disposal."

Beeware (Toga widget toolkit)

https://pybee.org/

This provides a multi target transpiler, supports many targets such as Android and iOS. It uses a generic widget toolkit (toga) that maps to the host interface calls.

Which One?

Both are active projects and their github accounts shows a fair amount of recent activity.

Beeware Toga like all widget libraries is good for getting the basics out to multiple platforms. If you have basic designs, and a desire to expand to other platforms this should work out well for you.

On the other hand, Chaquopy is a much more precise in its mapping of the python API to Android. It also allows you to mix in Java, useful if you want to use existing code from other resources. If you have strict design targets, and predominantly want to target Android this is a much better resource.

harvey
  • 2,945
  • 9
  • 10