buildozer不支持windows,这里默认linux环境安装完成(可以虚拟机和docker)
安装kivy和Buildozer
pip3 install Kivy -i https://pypi.tuna.tsinghua.edu.cn/simple pip3 install buildozer -i https://pypi.tuna.tsinghua.edu.cn/simple
安装buildozer打包需要的依赖文件
sudo apt update # 更新apt,可省略 sudo apt install -y git zip unzip openjdk-17-jdk autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
安装Cython
pip3 install Cython==0.29.19 -i https://pypi.tuna.tsinghua.edu.cn/simple
设置环境变量:存疑
添加如下内容:
export PATH=$PATH:~/.local/bin/
主要为了方便我们使用buildozer.py这个文件
安装编译文件
第一次启动buildozer时会自动安装,因此从我们启动一次即可
首先创建一个py文件,复制如下内容:
__version__ = "1.0.0" from random import random from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Ellipse, Line class MyPaintWidget(Widget): def on_touch_down(self, touch): color = (random(), 1, 1) with self.canvas: Color(*color, mode='hsv') d = 30. Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d)) touch.ud['line'] = Line(points=(touch.x, touch.y)) def on_touch_move(self, touch): touch.ud['line'].points += [touch.x, touch.y] class MyPaintApp(App): def build(self): parent = Widget() self.painter = MyPaintWidget() clearbtn = Button(text='Clear') clearbtn.bind(on_release=self.clear_canvas) parent.add_widget(self.painter) parent.add_widget(clearbtn) return parent def clear_canvas(self, obj): self.painter.canvas.clear() if __name__ == '__main__': MyPaintApp().run()
当年目录下,使用buildozer init生成buildozer.spec文件
buildozer init
然后开始打包
buildozer -v android debug
等待打包完成即可
错误1
第一次启动可能出现没有安装javac的情况,命令行:
sudo apt install default-jdk sudo apt install openjdk-11-jdk-headless sudo apt install ecj
错误2
linux FileNotFoundError: [Errno 2] No such file or directory: 'unzip'
原因是linux系统没有unzip,安装即可
apt-get install unzip
错误3
# sdkmanager path "/root/.buildozer/android/platform/android-sdk/tools/bin/s
可能是路径上某个压缩包未解压导致的,找到解压即可
错误4
若下载文件太慢或失败,多半需要科学上网!!!
错误5
configure: error: no acceptable C compiler found in $PATH
没有C语言编译器,安装即可
apt-get install gcc