Problems with building a flask app with p4a/buildozer

437 views
Skip to first unread message

Stupid User

unread,
May 25, 2017, 1:27:40 AM5/25/17
to kivy-...@googlegroups.com
Hello there, I am currently trying to make build a flask app and port
it to android. I have tried both the buildozer tool and p4a, but
haven't been successful with either, in the case of p4a, I don't even
get past the initial steps.
I have attached the logs for both the proccesses and also the relevant
buildozer.spec file, so I hope you can help me out with this.
buildozer.spec
error-buildozer.txt
error-p4a.txt

Stupid User

unread,
May 26, 2017, 12:28:36 AM5/26/17
to kivy-...@googlegroups.com
Well I managed to set up my p4a properly now and used an older sdk version that still has the proper commands. So I am able to compile an .apk file, but even with the most basic hello world app, I'm still stuck in an infinite Loading screen (not the kivy one with the kivy logo, but just the bacl text "Loading..." on a white screen). I enabled the internet permission and also declared the standard port for flask in my .p4a file. So, I'm not really sure what is wrong there. I inculded all my app, the .p4a-file and the apk-file I ended up with for reference.
 
25.05.2017, 13:27, "Stupid User" <stupid-u...@yandex.com>:
.p4a
main.py
MyApplication-0.1-debug.apk

Alexander Taylor

unread,
May 26, 2017, 7:25:08 AM5/26/17
to Kivy users support
Probably Python has crashed, you can debug with adb logcat, see https://kivy.org/docs/guide/android.html#debugging-your-application-on-the-android-platform

stupid-u...@yandex.com

unread,
May 27, 2017, 6:26:19 AM5/27/17
to Kivy users support
Oh hey there, I didn't know this would be posted in public here, but either way thanks for the suggestion, I will do that next and see if that will provide any help.

In the meantime just one simple question. The flask app for testing I used was the simple example from the flask homepage, saved as main.py and then simply pointed my .p4a file to the directory main.py was in. Now my question is, is that sufficient when building an app with p4a? Because I know that when I read up on building a kivy up with buildozer, it stated that I need a main.py file and buildozer automatically will use that one to start up the app. Is python4android with a webview app the same or do I need to do some additional configuring.
I just find it a bit weird, that the whole thing would already crash even using the simplest possible kind of app, especially since there didn't seem to be any problems with the p4a building proccess itself. (I have attached the log of that as additional information in this post). Also it seems I'm not the only person who has run into this roadblock. (See here) Either way, I will check the adb debug logs next and if the problem still persists get back to you.
log.txt

stupid-u...@yandex.com

unread,
May 27, 2017, 3:19:12 PM5/27/17
to Kivy users support
Oh well, I think I have found the problem by now. Not sure yet how to fix it though:

I/python  (20526): Run user program, change dir and execute entrypoint
I/python  (20526): main.py
I/python  (20526): Traceback (most recent call last):
I/python  (20526):   File "main.py", line 1, in <module>
I/python  (20526):     from flask import Flask
I/python  (20526):   File "/data/data/org.example.myapp/files/lib/python2.7/site-packages/flask/__init__.py", line 17, in <module>
I/python  (20526):     from werkzeug.exceptions import abort
I/python  (20526): ImportError: No module named werkzeug.exceptions
I/python  (20526): Python for android ended.

From what I can tell, it seems that it doesn't seem to find/have werkzeug within the android app at all. Not sure how to fix it, as explicitly adding "Werkzeug" to the requirements doesn't seem to help with it. Is this something I would need a recipe for or how could this be solved?



On Thursday, May 25, 2017 at 1:27:40 PM UTC+8, Stupid User wrote:

Geekademy

unread,
May 27, 2017, 3:35:48 PM5/27/17
to kivy-...@googlegroups.com, stupid-u...@yandex.com
Putting flask in your requirements should pull werkzeug in, no?

https://github.com/kivy/python-for-android/blob/master/pythonforandroid/recipes/flask/__init__.py


class FlaskRecipe(PythonRecipe):
...
python_depends = ['jinja2', 'werkzeug', 'markupsafe', 'itsdangerous', 'click']

stupid-u...@yandex.com

unread,
May 27, 2017, 11:54:55 PM5/27/17
to Kivy users support, stupid-u...@yandex.com
Well no, it obviously doesn't. As you can see, Flask is actually there and accessible, it only fails when trying to import werkzeug specifically. And seperately adding both flask and Werkzeug to the requirements, doesn't do anything either. Could the problem perhaps be that in the flask recipe file 'werkzeug' is written with a lower case 'w', while the pip/easy_install command seems to require a capital 'W' instead? Well, I'll just edit the recipe file accordingly and see if that does anything.

stupid-u...@yandex.com

unread,
May 28, 2017, 12:30:51 AM5/28/17
to Kivy users support, stupid-u...@yandex.com
Oh well, pip is case insensitive anyways, so no need to bother with that. However I just checked, and actually p4a doesn't put ANY of the dependencies into the app, not just werkzeug. How is that? When compiling the app it mentions those requirements and tells me that it will download them with pip if there is no recipe for them. But as far as I can tell, that never actually happens. So how to go about that?

stupid-u...@yandex.com

unread,
May 29, 2017, 1:23:14 AM5/29/17
to Kivy users support
Well, I managed to make it work now, by adding a recipe for each of the flask dependencies. But this is obviously not how this is supposed to work and right now I also cannot see how or where I could have possibly made a mistake. So if anyone would be willing to look into this and help me find out whether this is due to an error of mine or whether something about p4a isn't working properly I'd highly appreciate it.

stupid-u...@yandex.com

unread,
May 29, 2017, 9:22:05 AM5/29/17
to Kivy users support
Also for a different, only partially related question. What would be a good way to implement a local, offline database for using flask on android via webview. So far, I have stored all the information my app has to look up in one textfile (a list of addresses with one address per line) and in one json file (also a pretty long list of relatively basic dictionaries). The information in those files is pretty basic and only needs to be accessed for looking them up and reading them but both contain some 1000s of entries. And I cannot even read a few entries by importing it to python directly, without getting an internal server error. So does anyone have any suggestions what would be a good, simple and straigh-forward way to handle this?

Geekademy

unread,
May 30, 2017, 2:04:58 PM5/30/17
to kivy-...@googlegroups.com, stupid-u...@yandex.com
sqlite3

stupid-u...@yandex.com

unread,
May 31, 2017, 9:15:57 AM5/31/17
to Kivy users support, stupid-u...@yandex.com
Yeah, this is what I am trying to implement at the moment. Though related to that, could the fact that at least in its current deisgn the app is running on the standard command line flask test server, which as far as I know, isn't really meant for any kind of production version of an application turn out to be any kind of problem? Will using sqlite as a database mitigate that (in terms of performance) in any way or are those too unrelated in that regard. And if it is in fact not a good idea, is there anything that can be done about that fact to still make it work on android? Would be kind of a pity to go programming ahead only to later find out, the infrastructure of the app wouldn't even support it that well
Reply all
Reply to author
Forward
0 new messages