在WSL(Ubuntu)中使用Buildozer生成APK时出现STDERR错误
WSL(Ubuntu)下Buildozer编译APK失败排查方案
错误核心信息
# Command failed: ('/usr/bin/python3', '-m', 'pythonforandroid.toolchain', 'create', '--dist_name=kivyexample', '--bootstrap=sdl2', '--requirements=python3,kivy==2.0.0rc4,kivy_garden.graph,numpy', '--arch=arm64-v8a', '--arch=armeabi-v7a', '--copy-libs', '--color=always', '--storage-dir=/home/ajay/buildozer/kivy_examples/graphs/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a', '--ndk-api=21', '--ignore-setup-py', '--debug') # Error code: 1 # Buildozer failed to execute the last command # The error might be hidden in the log above this error # Please read the full log, and search for it before # raising an issue with buildozer itself. # In case of a bug report, please add a full log with log_level = 2
排查与解决步骤
1. 获取完整错误日志
错误提示明确问题可能隐藏在之前的日志中,需开启详细日志模式重新编译:
- 修改项目根目录下的
buildozer.spec文件,设置log_level = 2 - 或者直接执行命令:
buildozer android debug -v 2
重新编译后,查看完整日志中的具体报错(如依赖编译失败、版本冲突等)。
2. 修复依赖版本兼容性问题
当前使用的Kivy是候选版本(2.0.0rc4),且NDK版本(r25b)与NDK-api(21)可能不匹配:
- 升级Kivy到稳定版:修改
buildozer.spec中的requirements为python3,kivy==2.2.1,kivy_garden.graph,numpy,候选版本存在未修复的兼容性问题。 - 匹配NDK与NDK-api版本:
- 若坚持用NDK-api21,降级NDK到r21e(与api21匹配的稳定版本);
- 若保留NDK r25b,将
buildozer.spec中的ndkapi改为24+(r25b推荐的最低api版本)。
- 确认
kivy_garden.graph与指定Kivy版本兼容,必要时指定其稳定版本。
3. 解决权限冲突
当前以root用户执行编译,但项目目录属于ajay用户,易引发文件读写权限问题:
- 切换回ajay用户执行编译,避免使用sudo;
- 修复项目目录权限:
sudo chown -R ajay:ajay /home/ajay/buildozer/kivy_examples/graphs
4. 清理缓存重新编译
旧编译缓存可能导致依赖冲突,执行以下命令清理后重新编译:
buildozer android clean rm -rf .buildozer buildozer android debug
5. 补全系统依赖
确保WSL Ubuntu中安装了Buildozer编译所需的全部系统依赖:
sudo apt-get update sudo apt-get install -y git zip unzip openjdk-11-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev pip3 install --upgrade buildozer python-for-android
内容的提问来源于stack exchange,提问作者AjayR
相关产品推荐
相关产品推荐

