5

I have written a little program in python 3 and kivy. Now I want to build an .apk using buildozer and test the app on my android phone. Everything worked and I was able to install the app on the phone but the app crashed on startup.

The error log revealed, that the python enviroment of the apk was python 2.7 instead of 3. My question is therefore: Is it possible to build an apk with buildozer using a python 3 enviroment on android? Or do I have to rewrite the app in python2? Is there perhaps a possible hack to force buildozer to use python3?

Edit: I followed the steps suggested by inclement and got the following error:

 Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
  exec code in run_globals
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 747, in <module>
  main()
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 744, in main
  ToolchainCL()
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 323, in __init__
  getattr(self, args.command)(unknown)
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 105, in wrapper_func
  build_dist_from_args(ctx, dist, dist_args)
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 142, in build_dist_from_args
  build_recipes(build_order, python_modules, ctx)
File "pythonforandroid/build.py", line 560, in build_recipes
  recipe.build_arch(arch)
File "pythonforandroid/recipe.py", line 910, in build_arch
  self.build_cython_components(arch)
File "pythonforandroid/recipe.py", line 919, in build_cython_components
  command = sh.Command('python{}'.format(self.ctx.python_recipe.version))
File "/usr/lib/python2.7/site-packages/sh.py", line 788, in __init__
  raise CommandNotFound(path)
sh.CommandNotFound: python3.5
# Command failed: python -m pythonforandroid.toolchain create --dist_name=zugFart --bootstrap=sdl2 --requirements=kivy==1.9.1,python3crystax --arch armeabi-v7a --copy-libs

Edit 2: This seems to be a never ending story. With python3.5 installed I ran into this error:

collect2: error: ld returned 1 exit status
error: command 'arm-linux-androideabi-gcc' failed with exit status 1

With the time I used to advance from error to error it would be much smarter to simply change the code to python2.7 but now that I have so much time invested I just want to finally make it. :-)

So does somebody have an idea how to solve this issue?

Last Edit: I finally surrendered and changed my code to work with python 2.7. A good advice I have overseen during this process: If you using futures it is mandatory to add it to the requirements of the buildozer file. Otherwise the app crash on start with the "empty module" error message.

Now that my app works on the phone I'm finally happy :-) Thanks to inclement trying to help me with my problem.

1
  • I've had the same issue, got caught out with the difference in division operators, so I just added: from __future__ import division , and made sure my class inheritance worked with both 2.7 and 3. But I'd be interested to know if we can work in Python 3 with Kivy and expect to make it into an app...
    – Paul Brown
    Apr 10, 2016 at 23:54

3 Answers 3

3

I'm not sure if buildozer has a build option for python3 yet, but python-for-android supports it experimentally. You can use the new version of python-for-android by installing buildozer from its master branch and using the android_new target (buildozer android_new debug). If buildozer will work with its python3 option, you'd need to add python3crystax in the requirements (replace python2 if it's there), download the CrystaX NDK manually, and set buildozer's NDK path option to point to it. It might also be necessary to write kivy==1.9.1 in the requirements rather than just kivy.

Python3 builds are still in development to have all the features of the python2 ones, and need some clearing up including trimming the included files and compressing more. Some recipes also will no yet work with python3, though most do.

Edit: Unless your script is complicated and makes significant use of the major py2/py3 differences such as unicode handling, it probably wouldn't be difficult to use python2 instead. Since they're almost the same language, you probably don't need a 'rewrite', just a few small changes.

4
  • Thank you for your answer. You are right it is only a limited effort to make the app compatible to python2. If nothing works i will do it. However, I will try to get it running as you explained. At the moment I'm stuck with the issue that I haven't installed python 3.5 and my distribution has no official packages. I will let you know how the story ended :-)
    – magenulcus
    Apr 11, 2016 at 11:49
  • You don't need python3.5 to package apks with python3.5, the python build is built or copied locally (in this case from CrystaX's python builds).
    – inclement
    Apr 11, 2016 at 11:52
  • I added the error log at my starting post. If I don't have to install python3.5 why is this error occuring?
    – magenulcus
    Apr 11, 2016 at 12:06
  • Oh, my mistake, it currently does sort-of-depend on python3.5 (it might not technically, but the code currently requires it).
    – inclement
    Apr 11, 2016 at 13:10
0

first (at least few weeks ago) kivy did not work with python 3.5 correctly, use 3.4 instead; check Your imports as well sometimes it might be a problem with full module imports; example - don't use import math, but instead use from math import ...; And the best is to use pre-built buildozer image that You can download from kivy page; I'm using that and never had any problems except full imports and shebang line also should be deleted from code before building (sometimes makes problems)

1
  • Kivy claims python 3.7 support now. Does buildozer work with 3.7?
    – Jonathan
    Aug 22, 2018 at 21:32
0

The readme in 2018 claims python3 support if you compile buildozer from source, but not from pip:

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

I would include the build instructions but they are likely to change in a few months

1
  • @RodneySalcedo fixeed
    – Jonathan
    Jun 7, 2019 at 17:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.