1

I am trying to use Kivy Python-for-android, having no previous experience with android development. I have pyjnius installed, have all sdk, ndk and necessary files installed. My problem is I cannot find any tutorial, having spent many hours over many days trying to find one that goes from having everything installed to creating a working app on an android device taking in every step along the way.

Take the following text to speech example from pyjnius

from jnius import autoclass
Locale = autoclass('java.util.Locale')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
TextToSpeech = autoclass('android.speech.tts.TextToSpeech')

tts = TextToSpeech(PythonActivity.mActivity, None)
# Queue something in french
tts.setLanguage(Locale.FRANCE)
tts.speak('Bonjour tout le monde.', TextToSpeech.QUEUE_ADD, None)

I am lost as to how it all fits together and judging by what I have seen during my time spent googling for answers and tutorials, I am not alone.

1
  • I think for that moment the only information you can find on Kivy page - but there is no tutorial how to do this step by step. I still didn't try VirtualBox image (from Kivy page) to run linux distribution with tools to create apk for android. Commented Nov 30, 2013 at 20:06

1 Answer 1

2

I don't know of any large scale tutorials of this sort right now. (Edit: The closest thing I know of is dusty's tutorials, which is a set of 10 posts about how to build a kivy app, culminating in deploying to android).

However, I guess the real question here is what do you want to do? For many kinds of app you don't need to know anything at all about pyjnius, for instance. That's only necessary if you want to do some specific interaction with the android api that has not already been packaged in the python module provided by python-for-android. If you just want to (for instance) use the accelerometer or vibrate the phone, the details of pyjnius are not important to you.

from having everything installed to creating a working app on an android device taking in every step along the way.

I can't make a substitute for an in depth tutorial here, but I can try to clarify some of the process. In principle, you really only need to know about kivy itself to create an android app - that's the graphical framework, and a pure kivy app will more or less run identically across the different platforms.

If you want to make an android apk, python-for-android handles all the compilation for you (and uses pyjnius in the background for interfacing with the java api), but you won't need to know about the background details to have your app work fine. Python-for-android also provides a python module that lets you access some android apis, some of which is documented here. Actually, this doc is not very good right now in my opinion - worse than I remember even - but it's changing and improving. Python-for-android is developed quite actively.

You don't need any special knowledge to make an apk with python-for-android (or the buildozer tool, which is a friendlier frontend), the configuration is all just stuff like your app name and which python modules to compile in. Edit: In case you haven't seen it, the kivy documentation on building an apk is here. It's not a very in depth tutorial, but the process should not be very complex.

If you want to access parts of the android api that aren't already wrapped in python, that's when you need to look at pyjnius. Actually it's a joint process, and you also need to look at the (well documented) android api. autoclass wraps the java class in a python wrapper automagically, then everything else the example does calls the android api in this way - for instance, tts.speak is calling the speak method of the TextToSpeech class of the android api. Everything else in the example is doing the same sort of thing, though PythonActivity is a python-for-android class documented therein rather than in the android docs.

So to finish on the original question, what is it you want to do? If you want to make a graphical app without any particular platform specific stuff, just look at kivy, you don't need to know about pyjnius and so on. If you have some specific android functionality in mind, you're right that the existing documentation isn't very detailed, but I hope it's clear that it might not be very hard - like your example which just calls well documented java classes and methods, by name, from the python.

I also strongly recommend checking out the kivy mailing list and/or irc channel. I fully agree that kivy (or more particularly its associated projects like python-for-android and pyjnius) can be lacking in documentation or tutorials, but kivy does have a great helpful community. If you have any queries or questions about whatever your goal is, people there will be happy to discuss it.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the detailed response, I want to make an app that requires accessing the gps on an android handset. The parts that are most confusing are how to access the android api, how to test code on an avd for instance that has android specific code inside the kivy application. I know my lack of android experience is probably making this much harder but I still think a short video on coding, testing and finally deploying the app to an android device would really help a lot of people like myself.
Hmm...video tutorials, I was never really interested in them but maybe (maybe) I could give that a go. Would that be stuff like literally writing a short app and explaining the thought process along the way, or taking an app and typing in all the android build commands with explanation?
Yes, if you could make a video where you create a simple app that has android specific code using kivy, showing how it all ties together including how you might test the code and get it running on an android device. I have watched all kivy related videos including the one below suggested by qua-non and read a whole lot of docs etc.. but I think from the perspective of a novice programmer that all tutorials and related articles are aimed at experienced programmers.
If you could put a simple written or video tutorial together I think it would encourage a lot more, less experienced people like myself to use Kivy and python for andorid, which could only be good for the Kivy project long term.
I started a video series at youtube.com/watch?v=F7UKmK9eQLY&feature=youtu.be . I'm new to this, and it will take a little while to do more complex android stuff, but maybe it can help you in the future.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.