步骤:
1、安装 python3.8
更新pip源: pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
查看pip源: pip config list
2、创建Beeware环境
mkdir beeware
cd .\beeware\
py -m venv beeware-venv
beeware-venv\Scripts\activate.bat //激活虚拟env
pip install briefcase
3、编写Beeware应用
1.访问 API:使用jsonplaceholder(https://jsonplaceholder.typicode.com)作为数据源
2.安装第三库,例如:pip install httpx
3.briefcase dev #本地运行
4.briefcase update : 更新app代码
5.briefcase build : 编译app
6.briefcase run : 运行app
7.启动时提示module not found:
1.修改app全局依赖: key:[tool.briefcase.app.appname]
1.修改pyproject.toml,修改requires,将依赖添加至requires
2.添加时可以指定版本与版本范围,例如:httpx==0.19.0,httpx>=0.19
3.指定克隆仓库的路径: 如"git+https://github.com/encode/httpx"
2.修改指定平台的依赖: key:[tool.briefcase.app.appname.macOS、windows、linux、iOS、web、android]
1.修改pyproject.toml,修改requires,将依赖添加至requires
8.Python只在移动端:
1.在桌面平台: 任何pip能安装的都可以被添加到你的需求中
2.在移动平台: 只能使用纯Python包及包中不能包含二进制模块,numpy、scikit-learn、cryptography等不能在移动平台上使用
9. briefcase update -d #更新依赖
10.briefcase build #编译
11. briefcase run # 运行
4、 更新app代码
①打包之后修改代码使用briefcase dev可使修改生效,若使用briefcase run修改无效。
②使用briefcase update为现存的应用程序包更新代码;
使用 briefcase build命令重新编译app,
使用briefcase run 命令运行升级后的app,
使用 briefcase package 命令重新打包app以便分发。
③若想一步更改代码,更新app,迅速重新运行你的app,使用briefcase run -u 命令。
④如果你修改了app代码并想快速打包,可以使用briefcase package -u命令。
⑤对大多数日常开发,briefcase dev命令更便捷。
5、让APP更流畅
1.GUI事件循环: 当app正在处理一个事件,不能重绘也不能处理其他事件
2.异步编程: 使用 async 和 await 关键字实现
5、测试APP
1.briefcase dev -r #自动检查依赖安装情况
2.briefcase dev --test #执行测试
3.test_app.py #编写测试用例
4.briefcase run --test -r #运行时测试
5.briefcase run iOS --test、 briefcase run android --test #指定平台运行测试用例
6、依赖的三方库
pip install pywebview
pip install pydum
pip install pydub
pip install pygame
pip install baidu-aip
pip install playsound
pip install xlwt
pip install xlrd
pip install win32com
pip install bs4
briefcase build android -u -r --update-support --update-resources --test
briefcase build android -u -r --update-support --update-resources
briefcase run -u briefcase update android briefcase build android briefcase dev android briefcase update briefcase build briefcase dev
参考: