kivy-android

Kivy is a multi-touch python framework which works on Windows, OS X, Linux, iOS and Android.  Getting Kivy to run on Android, however, is a difficult task because the code needs to be first packaged in an App.  Here is a sure-fire way to make an Android App out of your python code.

On the Kivy website there are instructions on how to create an android package, but those instructions don’t work in Windows or OS X, and they skip lots of steps.

My solution is simple, get everything working in a virtual machine and do the packaging there.  For the record, the Kivy team did this first but:
(1) they used the Ubuntu operating system in the virtual machine which was very slow when I tried to use it and
(2) what I had to do to package my code was not made clear to me.
I did my best to create a virtual machine image which is as fast and as straightforward to use as possible.

LET’S GET STARTED

The first thing you will need is my linux virtual disk image.  It’s huge but it’s worth the wait.  The other thing you will need to do is to download Oracle VM Virtualbox and install it on your computer.  I won’t be giving detailed instructions on how to do this because it is easy to find out. Just get it running.

HERE IS THE IMPORTANT PART: Once you have Virtualbox running create a new VM using my vdi file as the hard disk. The only settings you need to have right is the operating system must be Linux and the version must be Ubuntu 32 bit.  If you want guidance you can check out this youtube video.  The video shows someone installing Virtualbox and setting up a VM using an existing vdi, which is exactly what you want to do.

LET’S BUILD!

Once the VM is booted up log in.  THE USERNAME AND PASSWORD IS osboxes.org

vbox1

By the way, thanks osboxes.org

Once logged in you should see the desktop:vbox2I put all the instructions to build the APK on the desktop wallpaper but I will go over them here with lots of screenshots.

1. Launch the Command Prompt (it’s actually called ROXTerm) by clicking on the icon.

vbox3

2. In the Command Prompt type the following (or Press the up key until you see it):
cd ~/Desktop/kivycode
Once you have that typed in, press the [enter] key. This just takes you into the ‘kivycode’ directory. You have to be in this directory for the command in step 4 to work.

3. In the Command Prompt type the following (or Press the up key until you see it):
cp ~/Desktop/buildozer.spec ~Desktop/kivycode
Once you have that typed in, press the [enter] key. This just copies the buildozer.spec file into the ‘kivycode’ directory for use. If you prefer you can copy the file using the GUI.

4. In the Command Prompt type the following (or Press the up key until you see it):
buildozer android debug
Once you have that typed in, press the [enter] key. This step actually makes the APK file. If everything went well, your APK should be created on the desktop. Get the APK onto your android device, install and launch!

linux4Python4Android

That’s it! You just built your first Android Installer Package!

NOW LET’S BUILD YOUR CODE!

Sure you just built an APK but the APK isn’t much use on the desktop of a VM. Furthermore it’s not your code.  Let’s sort that out.

Firstly we have to get files in and out of the VM.  My chosen solution was to use an external drive.  I just plugged one in and copied whatever I need onto it.  To then move the USB from the real computer and  the VM or vise versa, click ‘Devices > USBDevices’ in the virtualbox menu and click on the drive.

vbox4

The drive then appears in the VM

vbox5

If you don’t have an external drive you could just launch a browser and upload files to a service like Google Drive from within the VM.

vbox8

Now VirtualBox has a system by which you can set up a shared folder which can be seen by both the OS in VM and the Host OS but I couldn’t get it to work. If you can get it to work post me a comment telling me how. I’d appreciate it.

Now that we can get files in and out of the VM we can compile whatever code you have, once you know where to put it. Put it in the kivycode folder on the desktop.  To package your program just replace everything in the kivycode folder with your code.  Some things like Videos need special packaging settings and you should use the kivy framework but, for the most part, python 2.7 code would work just fine.

vbox6

The last thing you want to do before you compile your code is to copy the buildozer.spec file from the desktop into the kivycode folder and edit the copy as necessary.  The options are well described and there is more information about it online

Maybe you would like to edit the loading.png and icon.png but that’s all there is to it.  Build your python code into an app, collect the APK from the VM’s desktop and install it on your device.

Have fun!

61 thoughts on “The Fool-Proof guide to building an Android App with Python Kivy

  1. We’re a group of volunteers and opening a brand new scheme in your community.
    Your site provided us with valuable information to work on.
    You might have performed an amazing job and our whole neighborhood will most likely be thankful to
    you.

  2. Hey! Someone within my Myspace group shared this site with us thus i stumbled on look it over.
    I’m definitely enjoying the details. I’m book-marking
    and will also be tweeting this to my followers! Fantastic blog and excellent design and
    style.

  3. Normally I don’t read post on blogs, however I wish to claim that this write-up very
    forced me to have a look at and do so! Your writing style has become amazed me.
    Thanks, quite nice post.

  4. Hi, i do believe which i saw you visited my site thus i got to return the favor.I am just attempting to find things to improve my site!I suppose its ok to make use of some of your thoughts!!

  5. Wonderful goods on your part, man. I’ve understand your stuff previous to and you’re just
    extremely fantastic. I actually like what you’ve acquired here, really
    like what you are stating and the way for which you say it.
    You make it entertaining and you still deal with to hold it smart.

    I cant wait to read through far more of your stuff.
    This really is actually a tremendous internet site.

  6. Excellent post however , I was wondering if you could write a litte more on this topic?

    I’d be very thankful if you could elaborate a little bit further.
    Many thanks!

  7. Oh my goodness! Impressive article dude! Thanks a lot, However I am undergoing difficulties
    with your RSS. I don’t know the main reason why I am just unable to
    join it. Can there be anyone else getting the identical RSS
    problems? Anyone that knows the solution would you like to kindly respond?

    Thanx!!

  8. You actually help it become seem so easy with the presentation but I find this matter
    to be actually something that I feel I might never understand.
    It appears too complicated and extremely broad in my opinion.
    I am just anticipating for your upcoming post, I’ll try to obtain the
    hang of it!

  9. Have you contemplated creating an e-book or guest authoring
    on other sites? We have a blog dependant on about the same subjects
    you discuss and would love to obtain you share some
    stories/information. I am aware my subscribers would enjoy your job.
    If you’re even remotely interested, go ahead
    and send me an email.

  10. Because the network i use is not stable enough, every time the part i download reach 1/3 of all, it got failure.

    Could you please split the linux virtual disk image(LXLE14.04.3(32bit).vdi.zip) to many smaller part (every part less than 1GB, part1~part4)?

  11. I am aware this if off topic but I’m looking into starting my blog and
    was curious what all is required to get put in place?
    I’m assuming using a blog like yours would cost a pretty
    penny? I’m not too web savvy so I’m not 100% sure. Any suggestions
    or advice would be greatly appreciated. Appreciate it

  12. Howdy! I know this can be kinda off topic having said that i was wondering which blog platform are you using with
    this site? I’m getting fed up of WordPress because
    I’ve had issues with hackers and I’m considering
    options for one more platform. I might be great when you could
    point me toward an effective platform.

  13. Nice post. I learn something new and challenging on sites I stumbleupon every day.

    It’s always interesting to read through content from other authors and practice a little something from their sites.

  14. I had been recommended this blog by my cousin. I’m unclear whether this post is published by him
    as no person else know such detailed about my difficulty.

    You’re amazing! Thanks!

  15. Heya just wanted to give you a quick heads up and let you know a few of
    the images aren’t loading correctly. I’m not sure why but I
    think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  16. Does your website use a contact page? I’m having a
    tricky time locating it but, I’d like to send an email. I’ve got some creative ideas for the blog you
    might be interested in hearing. In any event, great website and that i look forward
    to seeing it improve with time.

  17. Thanks for ones marvelous posting! I definitely enjoyed reading it, you can be an incredible author.
    I am going to be sure to bookmark your blog site and could come back in the near future.
    I wish to encourage anyone to ultimately continue your great
    job, possess a nice day!

  18. Hello, I think your site might be having browser compatibility
    issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick heads up!
    Other then that, awesome blog!

  19. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three e-mails with the same comment.

    Is there any way you can remove people from that service?
    Thanks!

  20. Great work! This really is the kind of information that are supposed to
    be shared throughout the internet. Disgrace on Google for not positioning this build upper!
    Happen over and talk over with my site . Thanks =)

  21. You’ve made some excellent points there. I checked
    on the web for more information in regards to the issue and discovered a lot of
    people may go as well as your opinion of this page.

  22. You made some decent points there. I checked online for additional information in regards to
    the issue and found most individuals will go as well as your thoughts about this website.

  23. naturally just like your website however you should check the spelling on several of your respective posts.
    Several of them are rife with spelling issues and
    I to find it very bothersome to tell the reality however I will definitely come again again.

  24. Hello! This is kind of off topic but I need some guidance from an established blog.
    Is it hard to set up your own blog? I’m not very techincal but
    I can figure things out pretty quick. I’m thinking about making my
    own but I’m not sure where to begin. Do you have any
    ideas or suggestions? Thank you

  25. Heya! I realize this is sort of off-topic however I had to ask.
    Does building a well-established website such as yours require a massive amount work?
    I’m brand new to writing a blog but I do write in my journal daily.

    I’d like to start a blog so I can share my personal experience and views online.
    Please let me know if you have any ideas or tips for new aspiring blog owners.
    Thankyou!

  26. Nice weblog here! Also your site rather a great deal up extremely fast!
    What host have you been the usage of? Can I am
    just getting your affiliate link in your host? I desire my internet site loaded
    as fast as yours lol

  27. When I power on the new virtual box machine I get:

    invalid arch-independent elf magic
    Entering rescue mode
    grub rescue>

    What do I do?

  28. hi. please answer quickly. i follow your tutorial and try to boot into your vdi only to be prompted with the annoying message:

    invalid arch-independent elf magic
    Entering rescue mode
    grub rescue>

    just like the user above. please help. i really need an apk.

  29. Pingback: URL
  30. Pingback: live betting
  31. Pingback: gynodek
  32. Thanks for the tutorial, it’s really helpful for beginner like me. But by the way, how can I add opencv library to buildozer. Because when i want to complile and package 1 kivy+opencv program, it cannot open the build_opencv. Please help

  33. I’m curious to find out what blog platform you happen to be utilizing?
    I’m having some small security issues with
    my latest site and I’d like to find something more safe.
    Do you have any solutions?

  34. Pingback: Google
  35. Pingback: revize jerabu
  36. Pingback: ノロウイルス
  37. Pingback: Tam Coc Day Tour
  38. With havin so much written content do you ever run into any
    issues of plagorism or copyright violation? My blog has a lot of unique content I’ve
    either authored myself or outsourced but it seems a lot of it is popping it up all over the internet without my
    permission. Do you know any techniques to help stop content from being stolen? I’d definitely appreciate it.

  39. Pingback: php ecommerce
  40. Write more, thats all I have to say. Literally, it seems as
    though you relied on the video to make your point. You definitely know what youre talking about, why throw away your intelligence
    on just posting videos to your weblog when you could be giving us something enlightening to read?

  41. How do I install a newer version of kivy? I downloaded your virtual machine and it comes with kivy 1.7.2, I used the command: sudo pip –upgrade kivy, but it did not work.

Leave a Reply

Your email address will not be published. Required fields are marked *

*Captcha Code (Transcribe Below):