
Python on Android - mariuz
http://kivy.org/planet/2015/04/python-on%C2%A0android/
======
Macha
So, I've actually been working for the past while on a project to allow
building more native apps on Android using Python. It is built on the Kivy
tools, but I have had to make some changes to python-for-android specifically
because it's not as seperated from Kivy as the developers think. I've also had
to make a small change to PyJNIus, as it has a dependency on SDL when on
Android.

The reason I chose to work on this is while you can already create an
application using Kivy, it sort of exists in its own world compared to
standard Android apps. Because you don't have separate activities, you can't
really do stuff like have one of them be launched to handle a specific file or
URL (disclaimer: what I'm building can't either yet). There's also the same
issues you get with mobile apps that are web apps in an APK, where someone has
attempted to reimplement native UI widgets and there's certain behaviours that
are not quite right or missing, or you can't use them yet because they haven't
been replicated in your environment yet.

So basically what I'm doing is the Python equivalent of Xamarin.Android
([https://developer.xamarin.com/guides/Android/](https://developer.xamarin.com/guides/Android/)
) built on some of the Kivy tools. The idea is that you'd have the bulk of
your logic in cross platform Python and a thin UI layer for any platforms you
had. And in the future if someone made a similar thing for iOS, you could
build a layer overlying the two of them and get actually native behaviour on
both.

Overall I've gotten it to the stage where you can create activities, access
some standard UI elements and launch third-party apps via Python code, but
like I said, it's still at a pretty early stage.

I'd intended to open source it when it got to a more usable state, as it's
pretty much in proof of concept state atm. (bugs ahoy, tests and docs are very
lacking, feature coverage is low, setup is a PITA, and the API is too close to
the Java API to make for nice Python). These are problems I believe are
fixable. If you want to see the current state of it though, it's on
[https://bitbucket.org/tonyfinn/pydroid](https://bitbucket.org/tonyfinn/pydroid)
, but it's a bit off how far I'd like to be before sharing it.

~~~
andybak
Good god, here's a Kickstarter I'd get behind.

~~~
gedrap
Yes, grandparent, please consider this :)

------
WaxProlix
Kivy is really cool, but getting started on it sort of sucks. Lots of
compilation errors (especially if you're trying to install on windows) due to
its dependencies on pygame (and therefore cython, and therefore a particular
version of MSVS for the specific dll... all a hassle). The on-site tutorials
are sort of obtuse too, if you're looking to do UIs rather than games - until
other resources[1][2] became available, I sort of just gave up because it
didn't seem worth it to jump through the hoops for a new framework.

1 [http://inclem.net/pages/kivy-crash-course/](http://inclem.net/pages/kivy-
crash-course/)

2
[http://pythonthusiast.pythonblogs.com/230_pythonthusiast/arc...](http://pythonthusiast.pythonblogs.com/230_pythonthusiast/archive/1347_starting_to_use_kivy__developing_letter_of_heroes_an_android_alphabet_teaching_aid_for_kids_part_2_of_2.html)

~~~
lqdc13
On Ubuntu it's really easy though. This is why I switched OSes a few years
ago. Things are just easier if you use the same platform as other developers.

~~~
eli
Or just run a VM

~~~
nekopa
I recently switched to using vagrant for devving under windows and I have to
say that I am really enjoying it at the moment.

------
saintfiends
I also did give a try after I saw a post here on HN about a new release. I
wasn't very happy with it. There were many bugs that's a complete mess to get
started with.

I tried the example on their documentation and got it running on my Linux box
(which was very easy), but kept failing on Android due some missing
dependency. These issues are not listed on their website, giving the
impression it will just work out of the box. There by wasting a lot of time
for anyone wanting to give it a try. After much googling I got to find out
that SDL is not supported on Android for Kivy. You have to use PyGame and PIL.
PIL isn't maintained anymore, so you can't just do:

    
    
        pip2 install PIL 
    

Instead I had to run:

    
    
        pip2 install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
    

Pillow didn't work for me, complained that it was compiled for some other
platform. With that I was able to get rid of 'No text provider found'
dependency error, but still I can't open the application because of some
'Window provider not found' error. I left it at that.

It's a cool project and I'd like to see it succeed, but there is a long way to
go. I'd appreciate if someone could post a link on how to setup an environment
that setups Kivy to build for Android.

~~~
inclemnet
You shouldn't in principle need to worry about the difference between the sdl2
and pygame/sdl backends on Android, since kivy's own API is the same in either
case.

You don't need to install pil either (kivy preferentially uses other
providers), unless directly using it in your own code, in which case you can
include it in the android build by adding it to the python-for-android modules
string or buildozer requirements line (just 'pil', this is the name of an
internal recipe). If you have a window and text provider problem on android,
that indicates that something is wrong with the android build, and we can help
to debug if you provide the logs. I'm not sure offhand what problem would
allow the android build to complete but give this error, but it would probably
be revealed in the log.

~~~
saintfiends
This is more or less the same issue

[https://github.com/kivy/kivy/issues/3234](https://github.com/kivy/kivy/issues/3234)

I have since removed everything I setup, but I'll try to setup as I did before
and give a complete log.

~~~
inclemnet
Ah, thanks. I suspect this is a bug related to the transition to sdl2, though
I'm not sure what makes it present (it doesn't happen to everyone's android
build).

If you're interested, one thing to try is (if you're using buildozer) to put
'kivy==master' in the requirements line instead of just 'kivy'. This will
download the master branch, which may have a fix for this.

It not that, it's probably an issue somewhere in the python-for-
android/buildozer build process, so that log would be the most interesting. If
you're able to provide it that would be great, but thanks either way for
reporting it.

------
markdown
OT:

> the unimaginatively-named python-for-android project.

I love that name. Much better than the "imaginatively" named grunt, travis,
react, kivy, vagrant, etc.

~~~
acbart
I teach intro CS to non-majors, and having to explain terminology is
cumbersome. For instance, we call things "strings", "floats", and
"dictionaries". And then I make them download Anaconda so they can get Spyder
to write Python programs. I can't help but wonder what goes through their
heads.

~~~
V-2
Isn't "map" the proper CS term rather than a dictionary?

~~~
roger_333
They're called dictionaries (dicts) in Python.

~~~
V-2
And in .NET, but that's sort of an alias, while the scientific term is "map",
I believe.

------
bakabaka9
Kivy is a fun little library, not without its quirks, but overall I felt
comfortable with it.

In particular, it's nice how they built everything around GLSL shaders, this
allows for very interesting styling and visual effects.

Also personally I found that the easiest way of getting into Kivy is by
dissecting someone else's toy projects. E.g. there is this book with many
small programs written in Python with Kivy:
[https://www.packtpub.com/application-development/kivy-
bluepr...](https://www.packtpub.com/application-development/kivy-blueprints)
\-- it's an OK foundation. (You don't have to get the actual book, the source
code is here:
[https://github.com/mvasilkov/kb](https://github.com/mvasilkov/kb))

------
JustSomeNobody
I would much rather Google focus on Python than Dart for Android.

~~~
msl09
Too bad google suffers from a NIH syndrome.

~~~
V-2
As evidenced by using Java in the first place, and considering C# for Android
at one time ("If Sun doesn’t want to work with us, we have two options: 1)
Abandon our work and adopt MSFT CLR VM and C# language, or 2) Do Java anyway
and defend our decision, perhaps making enemies along the way")?

Or choosing Groovy-based Gradle as the main build system for Android?

Or not integrating Dart VM into Chrome?

Unlike Microsoft in their evil era - their policy has changed a lot since -
they don't seem to be pushing forward their own standards and inventions at
all costs, they seem very pragmatic about it.

~~~
vorg
> Or choosing Groovy-based Gradle as the main build system for Android

If that decision was made by more than just some obscure team buried deep
within Google's hierarchy, then why didn't Google start sponsoring the Groovy
manager and 2 developers when their funding was axed by Pivotal 2 months ago?

------
troymc
Other ways to use Python on Android (and iOS):
[http://www.mobilechameleon.com/toolkits-using-
python.html](http://www.mobilechameleon.com/toolkits-using-python.html)

------
tuxguy
Slightly related

[http://arstechnica.com/gadgets/2015/05/01/googles-dart-
langu...](http://arstechnica.com/gadgets/2015/05/01/googles-dart-language-on-
android-aims-for-java-free-120-fps-apps/)

------
JulianWasTaken
I'm not a mobile developer, so my interests in Python on Android were fairly
brief, but the last time I tried, python-for-android was nearly unusably
annoying to work with -- a chrooted normal linux with a real Python was miles
better.

The `android` module is also rather poor, IIRC it's just some RPC which would
be somewhat better off rewritten (a non-blocking version using twisted was a
thing I think I started on but never finished).

------
tubelite
I've been playing with SL4A (scripting languages for Android), but there
doesn't seem to be any active engagement by the project owners.

An actively maintained Python-for-Android with some way to access native
Android APIs is great news. I want to poll an Arduino-based web server and
send out SMSes if alert thresholds are reached, and a little python script
seems just the ticket.

------
giis
I'm playing with Kivy and Buildozer. Its important to begin with Kivy pre-
built VM otherwise it will be hard to setup things up on your own.

btw, anyone succeeded in adding python-fabric recipe to
[https://github.com/kivy/python-for-android](https://github.com/kivy/python-
for-android) ?

------
analog31
In my view a gaping hole in the Python for Android "stack" is the lack of
Tkinter. I know that there are technical hurdles, though I don't understand
them.

~~~
crshults
Wonder if some of the work from here [1] could be leveraged to fill that hole
faster.

[1]
[http://www.androwish.org/index.html/home](http://www.androwish.org/index.html/home)

~~~
analog31
That looks interesting, since one website said that lack of Tk/Tcl was the
obstacle.

I'm not desperate, for now. My interest was piqued when I got interested in
Python and Android almost simultaneously, was delighted to see that Android 3
would support Python, and bought an Android 3 tablet.

All of this is just in the name of recreational programming. My weird dream is
to be able to write and run my code on any computer. But an un-anticipated
side issue is that coding on a tiny screen is no fun at all at my advanced
age.

------
V-2
What about IDE support? Like an Android Studio plugin?

------
0xFFC
Is kivy production ready ?

~~~
fraytormenta
kivy is a lot better than it was 6 months ago - i like it

~~~
rplnt
I think I tried it maybe 2 years ago (I think) and back then it really
bothered me how big the resulting APKs were. Now, I think, most people don't
even care anymore.

