Kivy 打包成安卓apk - 图1
© dotmodus

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

Prerequisite: Java Home

Download openJDK 8 from here.

  1. sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev
  2. sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
  3. sudo apt install cython

1 install Buildozer

  1. ## install python
  2. sudo apt install python3.7
  3. ## install pip
  4. sudo apt install python3-pip
  5. ##
  6. sudo python3.7 -m pip install --user --upgrade Cython==0.29.19 virtualenv
  7. sudo python3.7 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple buildozer
  8. sudo apt update
  9. sudo apt install -y git zip unzip openjdk-8-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
  10. pip3 install --user --upgrade Cython==0.29.19 virtualenv # the --user should be removed if you do this in a venv
  11. or you can go and Check: [kivy-buildozer-installer.sh](https://github.com/zaemiel/kivy-buildozer-installer/blob/master/kivy-buildozer-installer.sh)
  12. ## add the following line at the end of your ~/.bashrc file
  13. export PATH=$PATH:~/.local/bin/

If you come with error buildozer debug error "[WARNING]" when i run buildozer andriod debug, please install lib below

  1. sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev

链接安卓手机, 开启USB debug模式;
进入 kivy 项目目录
测试项目:https://github.com/sevvalbrt/Todolist

  1. buildozer init
  2. buildozer android debug deploy run

手机有什么提示, 记得选择

可能会下一些东西. 等一下就好了

Kivy 打包成安卓apk - 图2

更多参考:
https://cycleuser.gitbooks.io/kivy-guide-chinese/content/15-Kivy-Pack-Android.html

Quick Test

Download a Kivy example

  1. git clone https://github.com/sevvalbrt/Todolist.git
  2. cd ToDolist
  3. buildozer init
  4. buildozer android debug deploy run

Kivy 打包成安卓apk - 图3
As this photo above, it’ll take a while…

The problem is you’ll download a bunch of libs and you’ll fail if one of the packages download fail.
[‘hostpython3’, ‘libffi’, ‘openssl’, ‘sdl2_image’, ‘sdl2_mixer’, ‘sdl2_ttf’, ‘sqlite3’, ‘python3’, ‘sdl2’, ‘setuptools’, ‘six’, ‘pyjnius’, ‘android’, ‘kivy’]

  • android-ndk-r19c-linux-x86_64.zip
  1. ## Buildozer failed to execute the last command
  2. ## The error might be hidden in the log above this error
  3. ## Please read the full log, and search for it before
  4. ## raising an issue with buildozer itself.
  5. ## In case of a bug report, please add a full log with log_level = 2

I got an error and it says I need to read the error code in full log file…

  1. Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

reference: lplj717 2019
It seems like I got a wrong version of jave.
So, I removed the new version and keep the jdk8.

And then, a new error arise:

  1. WARNING: Received a --sdk argument, but this argument is deprecated and does nothing.
  2. BUILD FAILURE: No main.py(o) found in your app directory. This
  3. file must exist to act as the entry point for you app. If your app is
  4. started by a file with a different name, rename it to main.py or add a
  5. main.py that loads it.

So… mv Main.py to main.py

and then:

  1. Could not find tools.jar. Please check that /home/ken/Soft/jre1.8.0_231 contains a valid JDK installation

reference: CUFFS 2017
So, there are some thing wrong with my JAVA environment, I download it from https://adoptopenjdk.net and export them in ~/.bashrc

Success

When the code shows as below, it means everything is down and you can upload apk file from bin to your Android phone:

  1. WARNING: Received a --sdk argument, but this argument is deprecated and does nothing.
  2. No setup.py/pyproject.toml used, copying full private data into .apk.
  3. Applying Java source code patches...
  4. Applying patch: src/patches/SDLActivity.java.patch
  5. Warning: failed to apply patch (exit code 1), assuming it is already applied: src/patches/SDLActivity.java.patch
  6. ## Android packaging done!
  7. ## APK myapp-0.1-armeabi-v7a-debug.apk available in the bin directory

ummmm… I fail to open this app in Huawei p30 pro. But I tried another more simple app and it succeed.


  1. sudo apt install install python3-dev

Erros

  1. RAN: /bin/tar xf /media/ken/Data/Kivy_env/Kivy2Py3.8.1MD0.104.2.dev0/.buildozer/android/platform/build-armeabi-v7a/packages/cython/0.29.15.tar.gz
  2. STDOUT:
  3. STDERR:
  4. /bin/tar: This does not look like a tar archive
  5. gzip: stdin: unexpected end of file
  6. /bin/tar: Child returned status 1
  7. /bin/tar: Error is not recoverable: exiting now

cypython file is damaged. Delete .buildozer/android/platform/build-armeabi-v7a/packages/cython to download it again

  1. def Seq_clean():
  2. F = open("clusttmp/result.aln-clustal_num.clustal_num").read()
  3. F = F.replace("\n\n\n","\n\n")
  4. F = F.split("\n\n")[1:]
  5. Result = ""
  6. Num = 0
  7. for head in F[0].split("\n"):
  8. for Seq in F:
  9. tmp = Seq.split("\n")[Num].split("\t")[0]
  10. if head !=Seq.split("\n")[Num]:
  11. tmp = tmp.split(" ")[-1]
  12. Result += tmp
  13. Result += "\n"
  14. Num +=1
  15. print(Result)
  16. Mark_list = []
  17. for i in Result.split('\n'):
  18. Mark_list += [i.split(" ")[-1]]
  19. while "" in Mark_list:
  20. Mark_list.remove("")
  21. Marked_list = []
  22. for seq in Mark_list:
  23. Marked_list += [MarkDown(seq)]
  24. for i, ii in zip(Mark_list, Marked_list):
  25. Result= Result.replace(i, ii)
  26. return Result
  27. def MarkDown(Text):
  28. Result = ""
  29. for i in list(Text):
  30. if i == "a" or i == "A":
  31. i = "[color=#fa937f]A[/color]"
  32. if i == "t" or i == "T":
  33. i = "[color=#1193ee]T[/color]"
  34. if i == "c" or i == "C":
  35. i = "[color=#51d673]C[/color]"
  36. if i == "g" or i == "G":
  37. i = "[color=#edcf1d]G[/color]"
  38. if i == "-" or i == " ":
  39. i = "[color=#ffffff]G[/color]"
  40. Result += i
  41. return Result

Enjoy~

本文由Python腳本GitHub/語雀自動更新

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗