Kivy application does not work on Android

后端 未结 1 453
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 22:54

I want write simple application in Python for Android using kivy. Sadly when I start example code I see only splash screen and few second later application finish work. There is

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 23:43

    I've used python-for android tool and faced with the same errors. But in my case, app didn't run at all - crashed from splash screen. Finally, I've found a solution. You can try the same way.

    So my pipeline was python3 + python-for-android (p4a tool, python-for-android, from master branch) + kivy (1.10.1)

    There is a file "_android.pyx" for android building recipe (full list of avaliable p4a recipes you can see by command p4a recipes). This file is, possibly, used by Buildozer, and exactly used by P4A during APK building procedure. You need to fix it.

    You may find it's location in Ubuntu (for example) via:

    sudo updatedb
    locate _android.pyx
    

    It's path should be something like:

    ~/.local/lib/python3.6/site-packages/pythonforandroid/recipes/android/src/android/_android.pyx
    

    There should be a string:

    python_act = autoclass(JAVA_NAMESPACE.decode('utf-8') + u'.PythonActivity')
    

    so you should change it - something like this:

    python_act = autoclass(str(JAVA_NAMESPACE) + u'.PythonActivity'),
    

    or just use some hardcode:

    python_act = autoclass("org/kivy/android/PythonActivity")
    

    Or there might be the other decode() usage in sources.

    The reason: differences between Python2 and Python3 - the decode() method is usable on the equivalent binary data type in either Python 2 or 3, but it can’t be used by the textual data type consistently between Python 2 and 3 because str in Python 3 doesn’t have the method decode function has different realisation in Python3. More details are here: pyporting features issues p4a's github

    Hope, it will help you somehow.

    0 讨论(0)
提交回复
热议问题