Building an APK with Buildozer and Kivy on OSX - Cython for Python3 Missing

511 views
Skip to first unread message

James Golding

unread,
Sep 10, 2019, 4:53:23 AM9/10/19
to Kivy users support
Hi all

I asked a question previously about this issue, although I was a lot further behind. After updating Buildozer and all the necessary components, such as Android NDK to version r20 and using the 'develop' branch for p4a, I've got rid of most of my errors. There's just this one. Please see attached.

Right after I have initiated the build with 'buildozer android debug' the outputs tell me that cython has been found but then a warning is produced:


[WARNING]: Cython for python3 missing. If you are building for  a python 3 target (which is the default) then THINGS WILL BREAK.



This then causes the build to break later on. I am really struggling to understand why I get this warning, which causes the break, when cython for python3 is definitely installed. I'd be grateful if you could take a look at the error output I have attached, to see what might be causing the error, and how I can correct it. I've attached the buildozer.spec file as well, just in-case you need it.


Thanks!

Buildozer Error Output - Cython for python3 missing
buildozer.spec

Nicolas Petitclerc

unread,
Sep 10, 2019, 5:49:18 AM9/10/19
to kivy-...@googlegroups.com
I have just managed to build an APK using p4a directly, on OSX with Python3.7, but using a conda venv and installing cython with: "conda install cython"
Using the "pip3 install cython" failed saying cython is not found - as you found.


--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a55deda5-4bdd-4abe-b002-5d2029f6de76%40googlegroups.com.

James Golding

unread,
Sep 10, 2019, 6:03:18 AM9/10/19
to Kivy users support
Oh that's interesting. At least it isn't just me who is having this issue with pip3 install cython.

I'm quite new to this and I think I've found some instructions for building directly with p4a but I would really appreciate it though if you could quickly show the steps you took to build it, to help me understand the process better, since you've done it successfully.

Thanks!


On Tuesday, September 10, 2019 at 9:49:18 PM UTC+12, Nicolas Petitclerc wrote:
I have just managed to build an APK using p4a directly, on OSX with Python3.7, but using a conda venv and installing cython with: "conda install cython"
Using the "pip3 install cython" failed saying cython is not found - as you found.


On Tue, Sep 10, 2019 at 10:53 AM James Golding <jgold...@gmail.com> wrote:
Hi all

I asked a question previously about this issue, although I was a lot further behind. After updating Buildozer and all the necessary components, such as Android NDK to version r20 and using the 'develop' branch for p4a, I've got rid of most of my errors. There's just this one. Please see attached.

Right after I have initiated the build with 'buildozer android debug' the outputs tell me that cython has been found but then a warning is produced:


[WARNING]: Cython for python3 missing. If you are building for  a python 3 target (which is the default) then THINGS WILL BREAK.



This then causes the build to break later on. I am really struggling to understand why I get this warning, which causes the break, when cython for python3 is definitely installed. I'd be grateful if you could take a look at the error output I have attached, to see what might be causing the error, and how I can correct it. I've attached the buildozer.spec file as well, just in-case you need it.


Thanks!

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Nicolas Petitclerc

unread,
Sep 10, 2019, 6:22:15 AM9/10/19
to kivy-...@googlegroups.com
FYI. I have also just succeeded building it with buildozer! Here's my spec file. 
So I guess the key thing is to install cython via conda.

Here's all my steps for the p4a method and conda install:


> conda create --name kivy_env python=3.7 -y 
> conda activate kivy_env

> pip3 install git+https://github.com/kivy/python-for-android.git
> conda install cython
> pip3 install --upgrade kivy

> touch ~/.android/repositories.cfg
> /Users/nic/Library/Android/sdk/tools/bin/sdkmanager "platforms;android-27”
> /Users/nic/Library/Android/sdk/tools/bin/sdkmanager "build-tools;26.0.2"
 
Add to .bashrc:
export ANDROIDSDK="/Users/nic/Library/Android/sdk"
export ANDROIDNDK=/Users/nic/projects/kivy/NDK/android-ndk-r20
export ANDROIDAPI="29"  # Target API version of your application
export NDKAPI="21"  # Minimum supported API version of your application

> source ~/.bashrc
> p4a apk --private /Users/nic/projects/kivy/pong_conda/ --package=org.test.mypongconda --name "MyPongConda" --version 0.1 --bootstrap=sdl2 --requirements=python3,kivy --debug 2>&1 | tee out.log

If it fails, run this before trying to build again
> p4a clean_builds && p4a clean_dists

So, that worked to produce an APK, but it crashes right away on my phone... now I need to figure out how to debug...



To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ed8cbe07-fa77-451c-a484-79d890b2fbbb%40googlegroups.com.
buildozer.spec

James Golding

unread,
Sep 10, 2019, 6:34:11 AM9/10/19
to Kivy users support
Thanks so much for the steps! I really appreciate it.

I had a look through your buildozer.spec file and it seems we're using mostly the same features, including the develop branch for p4a. You've used NDK 19b though, where I have 20. So you think if I install cython using Conda, instead of pip3, I won't have the error as I mentioned earlier, that you had before? I'm really glad to hear you managed to get buildozer to work!

I will try tomorrow to follow your steps for the p4a direct branch and I'll let you know how it goes.

For the version of your APK that crashed on your phone, is that the one produced by buildozer, or the one produced by the p4a direct method?

Nicolas Petitclerc

unread,
Sep 10, 2019, 7:01:36 AM9/10/19
to kivy-...@googlegroups.com
With p4a I used NDK 20, so that should work as well. (I just don't know how to use NDK20 with buildozer, how did you do that? it doesn't download it automatically...)
Both of them crashes... :/

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

James Golding

unread,
Sep 10, 2019, 3:31:25 PM9/10/19
to Kivy users support
Well for NDK20, to use with buildozer, I simply went to the Android NDK downloads page, donwnloaded and unzipped the NDK r20 and placed it in the same directory as the NDK 17c that I had previously been using. Then I just just put NDK 20 as a requirement in the buildozer.spec file and it worked fine.

I have downloaded and installed miniconda3 but unfortunately conda isn't recognised as a command in the terminal. In which directory should I be putting the miniconda3 file? Is there anything else I am supposed to do to get it to run?

That's a shame about both of them crashing. Could it be something to do with the python code for the app itself? I've made mine within PyCharm and I know it runs fine within that environment, so I am hoping it'll run fine once I manage to build it into an APK. I just haven't managed to do that yet!
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Robert Flatt

unread,
Sep 11, 2019, 1:52:08 AM9/11/19
to Kivy users support
>>>I've made mine within PyCharm and I know it runs fine within that environment, so I am hoping it'll run fine once I manage to build it into an APK.

Hoping is good, understanding leads to less surprises :)

Port "Hello World" first.

If the app references an external data file, remember that Android does not have a POSIX file system,......

If all the modules used by the app are Pure Python (or system functions) everything should be fine.
But if any of the modules are Python wrappers around, for example, C - then without 'special handling' its likely gonna crash.
The debugger will tell you what is the issue; simplest workaround is usually to replace the offending module with one of these (if you can)

James Golding

unread,
Sep 11, 2019, 2:52:13 AM9/11/19
to Kivy users support
You're right there. Far too many surprises for me trying to build the app for my liking.

Thanks for the advice! I'll take a look into it now. I just need to get it to build first, to see if there are any issues with it as an APK. I'll let you know!

James Golding

unread,
Sep 11, 2019, 4:03:20 AM9/11/19
to Kivy users support
So having downloaded miniconda3 and installing cython with that, there is no longer an issue with cython not being found, so thanks!  

Unfortunately now, there are another few errors. It gets almost to the end of the build, during the debug phase, which is good. However, there are a few different errors that I can see, relating to:

Execution failed for task ':processDebugManifest'.


WARNING: Received a --sdk argument, but this argument is deprecated and does nothing.

No compiled python is present to zip, skipping.

No setup.py/pyproject.toml used, copying full private data into .apk.

Applying Java source code patches...

Applying patch: src/patches/SDLActivity.java.patch

Warning: failed to apply patch (exit code 1), assuming it is already applied: src/patches/SDLActivity.java.patch


Do you have any idea what any of this means? I've attached the build output from the terminal, which contains all of the errors that are left. Hopefully you can come up with something.


Thanks!

Buildozer Error - processdebugmanifest

Nicolas Petitclerc

unread,
Sep 11, 2019, 8:12:22 AM9/11/19
to kivy-...@googlegroups.com
Your error is actually:
"Missing 'name' key attribute on element activity at AndroidManifest.xml:54:9-68:24"

I got the same error at some point... https://github.com/kivy/python-for-android/issues/1979
Which I never figure out, unfortunately..
But somehow when I used the conda method I described above, that error didn't occur anymore... so I'm a bit puzzled that you are getting that error now.


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bf19d672-2f9c-42c1-9ced-1f5937034959%40googlegroups.com.

Nicolas Petitclerc

unread,
Sep 11, 2019, 8:20:03 AM9/11/19
to kivy-...@googlegroups.com
Did you clear your .buildozer folder before building? just checking. 
 

James Golding

unread,
Sep 11, 2019, 3:33:03 PM9/11/19
to Kivy users support
I see. I didn't realise that was my actual error. It's a shame I am still having the error, even using miniconda but I suppose I will have to find a way of working it out. I did find this similar forum post:


Could this be an answer?

At least I am a lot closer to getting the app built than I was before. If you do think of anything in the meantime, please let me know. I'll let you know what I find.

James Golding

unread,
Sep 11, 2019, 3:41:46 PM9/11/19
to Kivy users support
I think I did, but what's the 'correct' way, just to be sure?

James Golding

unread,
Sep 12, 2019, 12:54:38 AM9/12/19
to Kivy users support
I realise that the .buildozer file I needed to delete to start over was just a hidden file, so I did that and re-ran the build. Sadly, it failed again, not even at the debugging stage this time. I popped the error code/build terminal transcript here: apilotslens.com/buildozer-error-after-build .

Any ideas? I really want to get this build to work soon...!

Nicolas Petitclerc

unread,
Sep 17, 2019, 4:56:21 AM9/17/19
to kivy-...@googlegroups.com
Hi,

For a clean build you can, be very careful and just do a 
rm -rf .buildozer

but a better (I think it prevents from redownloading averything) is to use:
buildozer android clean

Looks like you have a few build attempt in there, but at the end the error seems to be with the Python version:

  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/version.py", line 337, in _cmp

    if self.version < other.version:

TypeError: '<' not supported between instances of 'int' and 'str'

WARNING: Received a --sdk argument, but this argument is deprecated and does nothing.

No compiled python is present to zip, skipping.

I have never had that issue before, did you specify a python version somewhere? as a string where it should be an int (or the opposite...).

On my end, I tried about 100 variations of build and they always crash right away when I run the app on the device... so no luck/progress on my end unfortunately. :/





To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ca109a1f-4bb6-4f1f-b374-ac3884a82824%40googlegroups.com.

James Golding

unread,
Sep 17, 2019, 5:12:36 AM9/17/19
to Kivy users support
Hi

Well I used to just try:

buildozer android clean


But I don't think that was deleting everything, so what I'm doing instead is deleting the '.buildozer' file, which is a hidden file created in the directory of my app when I run:

buildozer android debug


I also use the 'buildozer android clean' as well, just to be safe. Unfortunately, I still haven't had any luck.

From your question, the only time I have specified a python version is in the buildozer.spec file, where for the requirements, I have put 

'python3,kivy'


All versions of python used (including frameworks etc.) are 3+ but there's nowhere else I specify a particular python version. What's more, this is only incredibly recent that I've been having this error. It didn't appear before. As I mentioned, previously I got to the debugging stage, with the right Java tools having been found (29.0.2 or something like that) which makes me think I have changed something, causing the type error. The only problem is, I've no idea what. Do you have any idea where I might have done this? I keep looking but I'm just not sure.

That's a shame you haven't got it to run yet! If I were able to get to that stage myself, I'd try and help you more. Does the app run in your python development environment? For example, mine is pycharm and it runs without a hitch there. 

Message has been deleted

Nicolas Petitclerc

unread,
Sep 17, 2019, 9:53:41 AM9/17/19
to Kivy users support
No idea, but I would suggest to create a new conda env and try to reinstall everything from scratch, perhaps with small changes. I often find different result... Basically stir the pot...

Yes, my kivy app (the hello world tutorial) runs on it's own. 

Perhaps you can try to build the hello world app first as well, to rule out some app related issues.

James Golding

unread,
Sep 17, 2019, 6:01:15 PM9/17/19
to Kivy users support
I might have to try that then. Whatever I am doing now certainly isn't working, so I should do something. You don't think part of it is because I have used the brew command to install buildozer itself, pip3.7 to install/update some of the packages (including things like python-for-android) and conda to install cython, do you? Would using different installation commands cause these issues?

I have actually built the hello world tutorial app, as well as the pong tutorial but I haven't tried building those. I will try them as well, to see if that causes any issues with buildozer when building. You never know. I can't imagine it would though since the errors seem to be related to the packages required to build. I haven't even got to the APK stage yet.

I also read a little bit about Android Studio and it seems that you can use it to analyse and troubleshoot any APK, even if it wasn't built through the studio. What about giving that a go, to see if it can pinpoint exactly what the issue is that you're having?

Nicolas Petitclerc

unread,
Sep 18, 2019, 6:55:10 AM9/18/19
to kivy-...@googlegroups.com
Using brew could definitely be part of it. I'm not sure which version it installs either.
Try pip buildozer, or master branch:

Actually, perhaps you can try to reproduce my issue? by following my steps detailed here:

It's true that your error doesn't seems related to the app itself. But using hello world, you would be sure of it.

I know quite exactly where the my app crashes, it's while initiating python. So it's quite early on as well. 




To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9437f795-e1a7-4b7a-8285-a429c0462780%40googlegroups.com.

James Golding

unread,
Sep 18, 2019, 6:43:09 PM9/18/19
to Kivy users support
I'll see what I can do about reinstalling it all then. It's pain but hopefully it'll work. I'm rapidly running out of space on my Airs tiny hard drive though...

I'll try and replicate yours as well when I get a moment. Hello world is such a basic app that there's very llittle in it that could cause the build to fail.I'll let you know what happens when I get round to it.Hopefully the Python won't be an issue for me as well.

I've actually been developing my app simultaneously in Android Studio, whilst this hasn't been working. It uses Kotlin, which is different from Python but easy enough to pick up if you can programme with Python already. This way, it is working fine. I just wish the buildozer way would work also.
...

Nicolas Petitclerc

unread,
Sep 20, 2019, 5:52:57 AM9/20/19
to kivy-...@googlegroups.com
I finally managed to play Pong on my phone! 🎉🎉🎉

But I used a workaround - I installed Ubuntu 19.04 on VirtualBox. As it seems most people using Kivy are using Linux... 
I use Google Drive to shuffle files around. This is not an ideal setup, but at least I can get started on the app.

If that's an option for you, here's the exact steps I used:

# Kivy install (via miniconda)
Download installer from https://docs.conda.io/en/latest/miniconda.html
bash Downloads/Miniconda3-latest-Linux-x86_64.sh  
(Version 4.7.10)


conda create --name kivy_env python=3.7 -y
conda activate kivy_env

mkdir kivy
cd kivy
mkdir hello_world
(Copy main.py in there)

# Dependencies
sudo apt update
sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5
sudo apt install -y libffi-dev  <-- I was getting a ctypes error without this lib
pip3 install --upgrade cython virtualenv

cd ..
sudo apt install git
git clone https://github.com/kivy/buildozer.git
pip install ./buildozer


# add the following line at the end of your ~/.bashrc file
nano ~/.bashrc
export PATH=$PATH:~/.local/bin/
source  ~/.bashrc

cd ../hello_world
buildozer init
buildozer -v android debug


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/34cd48f8-7d93-4ba8-8695-db4a1c53a618%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages