pip3 install buildozer
就用它 https://github.com/kivy/kivy/tree/master/examples/demo/pictures
buildozer init
vim buildozer.spec
按照 Buildozer Doc说的,Android on Ubuntu 18.04 (64bit) 应该:
sudo pip install --upgrade cython==0.28.6
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386
buildozer -v android debug
它会下载 Android SDK, NDK 和其他工具, 占据 ~/.buildozer 大约 3.9GB 空间和 ./.buildozer 大约 1.3 GB, 如果你只装了 python3 和 pip3
但即使这样它也会崩, 要确保没有 [WARNING] 叫你安装其他的包, 并且经常Bing.
如果它说 there is no file called xyz.so, 试试:
locate xyz.so
ln -s path/to/exist/so /usr/lib/xyz.so
嫌慢的话早上下载会快一点
apk 文件在文件夹 ./bin 里面
你可以把它上传到云再下载到手机上(就像我之前做的一样),但我建议还是开启USB调试,把手机直接连到电脑上,运行:
buildozer android deploy
apk 文件就会传到手机上并安装。再运行:
buildozer android run logcat 2>&1 >/dev/null | grep 'python' > filter.out
Note:
an android device can only connect to a virtual machine or the PC at one time, configure it carefully
buildozer writes adb logcat info to STDERR, so use
2>&1
to redirect it to STDOUTuse grep to get all info related to python, since logcat has too much info to read
logcat won’t stop automatically, so kill it when your app fiinishes
finally, write all to a file to be easily read.
我在安装 kivy 之前就使用了 buildozer,然后我的第二个应用就因为 pip 安装的kivy 版本高于 build 版本而崩了。所以我重装 kivy 使得版本匹配。