2025年kivi android打包

kivi android打包1 背景 正常开发中 我们大多在 window 下开发好我们的 App 我们需要打包为 ApK 然后在我们的手机安装才能运行 官方给出了 3 种打包方案 Buildozer Python for Android Kivy Launch 当然开发者大多打包在 Linux 环境 因为我们在 Windows 下的环境配置比较繁琐

大家好,我是讯享网,很高兴认识大家。

 

1.背景

正常开发中,我们大多在window下开发好我们的App,我们需要打包为ApK,然后在我们的手机安装才能运行,官方给出了3种打包方案Buildozer,Python-for-Android,Kivy Launch,当然开发者大多打包在Linux环境,因为我们在Windows下的环境配置比较繁琐,当然官方给了几种方法都是基于Linux的(https://github.com/kivy/buildozer 官方文档)。

2.Biuldozer打包才是常态

Buildozer打包的好处在于可以自动构建整个打包过程,该工具会自动下载并设置Python-for-Android,包括了Android SDK 和 NDK,这种方式新手最适合(使用这个一个工具,你可以打包IOS,android,osx等)

3.步骤

物理部署

1.安装buildozer

[root@pand_1_2 hello]# pip3 install buildozer -i https://pypi.doubanio.com/simple/

讯享网

 

容器化部署(centos7)

1.安装docker

讯享网[root@pand_1_2 hello]# pip install DockerDeploy (本人写的,也可以使用官方安装容器方法)

2.安装镜像

[root@pand_1_2 hello]# docker pull kivy/buildozer

3.运行一个容器

讯享网docker run -itd --name buildozer --privileged=true --volume "$PWD":/home/user/hostcwd --entrypoint /bin/bash kivy/buildozer

4.进入容器

[root@pand_1_2 hello]# docker exec -it buildozer /bin/bash

 

共有步骤

修改Python-for-Android代码拉取地址(改为国内源),如下:


讯享网

讯享网[root@pand_1_2 hello]# vim /usr/local/python3/lib/python3.6/site-packages/buildozer/targets/android.py

 

 

将kivy改为mirrors,到github.com替换gitee.com

 

加入环境变量

[root@pand_1_2 hello]# vim ~/.bashrc export PATH=$PATH:/usr/local/python3/bin/ [root@pand_1_2 hello]# source ~/.bashrc

 

即可开始打包

讯享网[root@pand_1_2 hello]# buildozer init (生成初始化配置文件,这个配置文件修改请参考官方文档) [root@pand_1_2 hello]# buildozer android debug

看到如下画面即成功(注意第一次打包很慢,有些需要安装环境,国外网速太慢,也有可能因为网速原因安装失败,需要多试几次,否则就用vpn)

[root@pand_1_2 hello]# buildozer android debug # Check configuration tokens Buildozer is running as root! This is not recommended, and may lead to problems later. Are you sure you want to continue [y/n]? y # Ensure build layout # Check configuration tokens # Preparing build # Check requirements for android # Run 'dpkg --version' # Cwd None /bin/sh: dpkg: 未找到命令 # Search for Git (git) # -> found at /usr/bin/git # Search for Cython (cython) # -> found at /usr/local/python3/bin/cython # Search for Java compiler (javac) # -> found at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/bin/javac # Search for Java keytool (keytool) # -> found at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/keytool # Install platform # Run 'git config --get remote.origin.url' # Cwd /home/lijiacai/kivy_test/hello/.buildozer/android/platform/python-for-android https://gitee.com/mirrors/python-for-android.git # Run 'git branch -vv' # Cwd /home/lijiacai/kivy_test/hello/.buildozer/android/platform/python-for-android * master 1b3b0e3 [origin/master] Merge pull request #2225 from kivy/release-2020.06.02 # Run '/usr/local/python3/bin/python3.6 -m pip install -q --user \'appdirs\' \'colorama>=0.3.3\' \'jinja2\' \'six\' \'enum34; python_version<"3.4"\' \'sh>=1.10; sys_platform!="nt"\' \'pep517<0.7.0"\' \'toml\'' # Cwd None WARNING: You are using pip version 19.1.1, however version 20.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. # Apache ANT found at /root/.buildozer/android/platform/apache-ant-1.9.4 # Android SDK found at /root/.buildozer/android/platform/android-sdk # Recommended android's NDK version by p4a is: 19c # Android NDK found at /root/.buildozer/android/platform/android-ndk-r19c # Check application requirements # Check garden requirements # Compile platform # Run '/usr/local/python3/bin/python3.6 -m pythonforandroid.toolchain create --dist_name=HelloWorld --bootstrap=sdl2 --requirements=python3,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/home/lijiacai/kivy_test/hello/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21' # Cwd /home/lijiacai/kivy_test/hello/.buildozer/android/platform/python-for-android [INFO]: Will compile for the following archs: armeabi-v7a [INFO]: Found Android API target in $ANDROIDAPI: 27 [INFO]: Available Android APIs are (27) [INFO]: Requested API target 27 is available, continuing. [INFO]: Found NDK dir in $ANDROIDNDK: /root/.buildozer/android/platform/android-ndk-r19c [INFO]: Found NDK version 19c [INFO]: Getting NDK API version (i.e. minimum supported API) from user argument [INFO]: ccache is missing, the build will not be optimized in the future. [INFO]: Found the following toolchain versions: ['4.9'] [INFO]: Picking the latest gcc toolchain, here 4.9 [INFO]: No existing dists meet the given requirements! [INFO]: No dist exists that meets your requirements, so one will be built. [INFO]: Found a single valid recipe set: ['hostpython3', 'libffi', 'openssl', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'sqlite3', 'python3', 'sdl2', 'setuptools', 'six', 'pyjnius', 'android', 'kivy'] [INFO]: The selected bootstrap is sdl2 [INFO]: # Creating dist with sdl2 bootstrap [INFO]: Dist will have name HelloWorld and requirements (python3, kivy) [INFO]: Dist contains the following requirements as recipes: ['hostpython3', 'libffi', 'openssl', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'sqlite3', 'python3', 'sdl2', 'setuptools', 'six', 'pyjnius', 'android', 'kivy'] [INFO]: Dist will also contain modules (certifi) installed from pip [INFO]: Dist will be build in mode debug [INFO]: -> directory context /home/lijiacai/kivy_test/hello/.buildozer/android/platform/build-armeabi-v7a/build/bootstrap_builds/sdl2 [INFO]: <- directory context /home/lijiacai/kivy_test/hello/.buildozer/android/platform/python-for-android [INFO]: Recipe build order is ['hostpython3', 'libffi', 'openssl', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'sqlite3', 'python3', 'sdl2', 'setuptools', 'six', 'pyjnius', 'android', 'kivy'] [INFO]: The requirements (certifi) were not found as recipes, they will be installed with pip. [INFO]: # Downloading recipes [INFO]: Downloading hostpython3 [INFO]: -> running mkdir -p /home/lijiacai/kivy_test/hello/.buildozer/android/p...(and 46 more) [INFO]: -> directory context /home/lijiacai/kivy_test/hello/.buildozer/android/platform/build-armeabi-v7a/packages/hostpython3

备注:如果存在文件无访问权限,请修改权限即可

讯享网[root@pand_1_2 hello]# sudo chmod 777 -R /home

我并没有完全按照官方文档进行部署,因为我希望我经过第一次安装后我的环境不需要重新安装,以后在打包时,就会很快

以上教程仅供学习,环境指正

 

 

 

小讯
上一篇 2025-04-04 09:19
下一篇 2025-04-05 12:44

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/85600.html