9q13nh 发表于 2024-8-17 17:46:11

运用python kivy构建手机可安装的apk软件,亲测有效


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">可将python kivy框架编写的程序打包成apk文件,亲测有效。欢迎小伙伴们点赞<span style="color: black;">保藏</span>,以备下次<span style="color: black;">必须</span>时<span style="color: black;">能够</span>快速找到。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面是<span style="color: black;">自己</span><span style="color: black;">经过</span><span style="color: black;">持续</span>尝试,<span style="color: black;">最终</span><span style="color: black;">能够</span>成功将自定义程序打包<span style="color: black;">成为了</span>手机能安装的app文件,<span style="color: black;">首要</span>要<span style="color: black;">保准</span>网络足够好,在打包编辑过程中会有<span style="color: black;">非常多</span>东西<span style="color: black;">必须</span>在github上下载,</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">准备:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">系统:Ubuntu 20.04.6 LTS</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">python 版本:Python 3.8.10 系统自带<span style="color: black;">就可</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">kivy 版本:1.9.1(由自己<span style="color: black;">实质</span>程序编写的版本为准)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">buildozer版本 1.5.0</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">cython: 3.0.1 (看官网上kivy2.2.1对应的版本是3.x.x)</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/44ea62cc2cd147ea867271db3b36124b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894046&amp;x-signature=eLusFuNlikSQgejOnGGfecHnr1M%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">登录官网:https://github.com/kivy/kivy 查看</p>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、</span>安装lib库</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.1</p>sudo apt-get <span style="color: black;">update</span>
    sudo apt-<span style="color: black;">get</span> dist-<span style="color: black;">upgrade</span>
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> make git zip unzip dp<span style="color: black;">公斤</span> libffi-dev zlib1g-dev
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> <span style="color: black;">build</span>-essential libgl1-mesa-dev libgles2-mesa-dev python3-dev
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> autoconf libtool libevent-dev
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> openjdk<span style="color: black;">-11</span>-jdk -y
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> <span style="color: black;">build</span>-essential python-dev python-setuptools
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span>libncursesw5-dev libgdbm-dev libc6-dev
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> zlib1g-dev libsqlite3-dev tk-dev
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> libssl-dev openssl cython
    sudo apt-<span style="color: black;">get</span> <span style="color: black;">install</span> python3-ip<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、</span> 安装buildozer</p><span style="color: black;">sudo</span>pip3 install buildozer<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">三,打包成apk文件</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以上准备工作<span style="color: black;">已然</span>做完,<span style="color: black;">第1</span>次打包会下载所有<span style="color: black;">必须</span>的包,<span style="color: black;">因此</span>打包时<span style="color: black;">必须</span>网络畅通,许多包都是<span style="color: black;">必须</span>在github上下载,<span style="color: black;">因此</span>需稳定<span style="color: black;">拜访</span>github,<span style="color: black;">能够</span>找一个加速<span style="color: black;">拜访</span>的工具,</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.1 加速器下载<span style="color: black;">位置</span>:</p>https://github.com/dotnetcore/FastGithub
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>github网络不稳定,<span style="color: black;">能够</span>下载加速器</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/58d26248b20b4860abdf7365eea8bac0~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894046&amp;x-signature=Q5VOCVVBGdKq%2FZoyWAWAHwMulro%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将加速器放在linux系统上某个自定义目录下:</p><span style="color: black;">export</span> http_proxy=http://127.0.0.1:38457 <span style="color: black;">#设置网络代理</span>export https_proxy=http://127.0.0.1:38457
    env | grep -i proxy<span style="color: black;">#查看当前代理设置</span>
    sudo ./fastgithub <span style="color: black;">#将程序解压后执行</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.2 初始化项目</p><span style="color: black;">cd</span> <span style="color: black;">项目路径</span>
    <span style="color: black;"><span style="color: black;">创立</span>main.py文件</span>
    <span style="color: black;">sudo</span> <span style="color: black;">buildozer init</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.3 修改修改buildozer.spec文件(Cython<span style="color: black;">意见</span>写入,其他第三方模块<span style="color: black;">按照</span><span style="color: black;">必须</span>写入)</p><span style="color: black;">requirements</span> = kivy==<span style="color: black;">2.2</span>.<span style="color: black;">1</span>,Cython==<span style="color: black;">3.0</span>.<span style="color: black;">1</span> <span style="color: black;">#将<span style="color: black;">必须</span>导入的第三方包写入</span>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/cead2e82aa6d4d86b0e0b12b29c2efc3~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894046&amp;x-signature=qEEAMEPQlqNbAttmE22QIwIUvs8%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">requirements</p>
    </div><span style="color: black;">sudo</span> buildozer -v android <span style="color: black;">debug</span> <span style="color: black;">#再项目所在目录执行</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">成功执行完命令后会在项目所在目录下的bin目录下生成apk软件</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/27a9fff70923419aa5d40df5dd23e5d2~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894046&amp;x-signature=30rcdPzGsGuaUS9dQqROxA0RnDU%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">四,再次打包其他程序</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1. 进入到您要打包成 APK 的软件项目目录中。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2.删除程序目录下原有的</span><span style="color: black;">buildozer.spec</span>文件,删除程序下原程序的代码文件,切记不要删除.开头的文件,<span style="color: black;">而后</span>重新构建</p><span style="color: black;">rm</span> <span style="color: black;">-rf buildozer</span>
    <span style="color: black;">buildozer</span> <span style="color: black;">init </span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4.编辑新生成的buildozer.spec 文件将<span style="color: black;">必须</span>加载的第三方文件,<span style="color: black;">已然</span><span style="color: black;">必须</span>打包进程序的文件结尾加进去(最好都加上Cython,我用的是3.0.1版本,其他第三方模块<span style="color: black;">必须</span>写入)</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7f737c5e08a245eeb63805a0b766e279~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894046&amp;x-signature=z3MEIQiqp4IXM4MxjE4maokR5jg%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">buildozer.spec文件</p>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5. <span style="color: black;">运行命令sudo buildozer -v android debug<span style="color: black;">或</span>sudo </span><span style="color: black;">buildozer android release</span><span style="color: black;">(<span style="color: black;">详细</span><span style="color: black;">按照</span>您的需求<span style="color: black;">选取</span>)来构建 APK。</span></p><span style="color: black;">sudo</span> buildozer -v android <span style="color: black;">debug</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">注:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">有时候,buildozer的缓存可能<span style="color: black;">引起</span>文件冲突。你<span style="color: black;">能够</span>尝试清理buildozer的缓存,<span style="color: black;">而后</span>再次运行打包命令。<span style="color: black;">能够</span><span style="color: black;">经过</span>运行以下命令来清理缓存:</span></p><span style="color: black;">buildozer</span> distclean<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">意思是<span style="color: black;">运用</span> buildozer 工具在 Android 环境中进行构建,并清理构建过程中生成的临时文件和构建输出。</span></p><span style="color: black;">sudo</span> buildozer -v android clean<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">总结:</strong>再打包apk软件环境的过程中会<span style="color: black;">显现</span><span style="color: black;">各样</span>的问题,<span style="color: black;">大众</span><span style="color: black;">必定</span>要看日志输出的是什么,<span style="color: black;">第1</span>大问题<span style="color: black;">便是</span>网络问题,有些包<span style="color: black;">必须</span>反复执行buildozer多次<span style="color: black;">才可</span>下载。尤其到<span style="color: black;">必须</span>下载jpeg zlip文件的时候,<span style="color: black;">倘若</span><span style="color: black;">半途</span>网络断掉,<span style="color: black;">必须</span>重新删除<span style="color: black;">已然</span>下载的文件再次执行构建命令。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面是我最后遇到的问题:</p># <span style="color: black;">unzip</span> <span style="color: black;">gradle-7</span><span style="color: black;">.4</span><span style="color: black;">.1-all</span><span style="color: black;">.zip</span> <span style="color: black;">Archive</span>: <span style="color: black;">gradle-7</span><span style="color: black;">.4</span><span style="color: black;">.1-all</span><span style="color: black;">.zip</span> <span style="color: black;">End-of-central-directory</span> <span style="color: black;">signature</span> <span style="color: black;">not</span>
    <span style="color: black;">found</span>. <span style="color: black;">Either</span> <span style="color: black;">this</span> <span style="color: black;">file</span> <span style="color: black;">is</span> <span style="color: black;">not</span> <span style="color: black;">a</span> <span style="color: black;">zipfile</span>, <span style="color: black;">or</span> <span style="color: black;">it</span> <span style="color: black;">constitutes</span> <span style="color: black;">one</span> <span style="color: black;">disk</span> <span style="color: black;">of</span> <span style="color: black;">a</span> <span style="color: black;">multi-part</span> <span style="color: black;">archive</span>. <span style="color: black;">In</span> <span style="color: black;">the</span>
    <span style="color: black;">latter</span> <span style="color: black;">case</span> <span style="color: black;">the</span> <span style="color: black;">central</span> <span style="color: black;">directory</span> <span style="color: black;">and</span> <span style="color: black;">zipfile</span> <span style="color: black;">comment</span> <span style="color: black;">will</span> <span style="color: black;">be</span> <span style="color: black;">found</span> <span style="color: black;">on</span> <span style="color: black;">the</span> <span style="color: black;">last</span> <span style="color: black;">disk</span>(<span style="color: black;">s</span>) <span style="color: black;">of</span> <span style="color: black;">this</span>
    <span style="color: black;">archive</span>. <span style="color: black;">unzip</span>: <span style="color: black;">cannot</span> <span style="color: black;">find</span> <span style="color: black;">zipfile</span> <span style="color: black;">directory</span> <span style="color: black;">in</span> <span style="color: black;">one</span> <span style="color: black;">of</span> <span style="color: black;">gradle-7</span><span style="color: black;">.4</span><span style="color: black;">.1-all</span><span style="color: black;">.zip</span> <span style="color: black;">or</span>
    <span style="color: black;">gradle-7</span><span style="color: black;">.4</span><span style="color: black;">.1-all</span><span style="color: black;">.zip</span><span style="color: black;">.zip</span>, <span style="color: black;">and</span> <span style="color: black;">cannot</span> <span style="color: black;">find</span> <span style="color: black;">gradle-7</span><span style="color: black;">.4</span><span style="color: black;">.1-all</span><span style="color: black;">.zip</span><span style="color: black;">.ZIP</span>, <span style="color: black;">period</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">大概意思是gradle-7.4.1-all.zip <span style="color: black;">无</span>下载成功,其实在执行buildozer构建的时候会提示下载这个文件的位置,<span style="color: black;">大众</span><span style="color: black;">能够</span>提前下载好,等构建过程中<span style="color: black;">显现</span>上面的问题时,找到gradle-7.4.1-all.zip存放的位置,删除原来的文件,将自己下载的文件放到此处。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">总之,制作打包环境真的是<span style="color: black;">很难</span>啊,做好环境后给自己的虚机做个快照,<span style="color: black;">以避免</span>系统出问题再次构建打包环境。</p>




星☆雨 发表于 2024-8-22 23:57:56

外贸网站建设方法 http://www.fok120.com/

听听海 发表于 2024-9-9 17:19:41

认真阅读了楼主的帖子,非常有益。

b1gc8v 发表于 2024-10-2 05:55:29

我完全同意你的观点,说得太对了。

wrjc1hod 发表于 2024-10-3 23:40:25

谢谢、感谢、感恩、辛苦了、有你真好等。

1fy07h 发表于 2024-10-29 02:17:24

外贸B2B平台有哪些?

nykek5i 发表于 2024-10-30 09:41:27

感谢楼主分享,祝愿外链论坛越办越好!
页: [1]
查看完整版本: 运用python kivy构建手机可安装的apk软件,亲测有效