// 用清华大学的镜像源要快许多
pip install plyer -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install jnius -i https://pypi.tuna.tsinghua.edu.cn/simple/
其实plyer库最终也会调用到jnius库,所以必须安装jnius库,但是安装时可能会报错,或者在调用jnius库报错。
原因是没有配置环境变量JDK_HOME,本来是需要安装jdk,但是上一篇文章提到的虚拟机系统中已经安装好了jdk1.8.0_121,所以只需要配置一下JDK_HOME环境变量就行。
在虚拟机/etc目录下找到profile文件,当然文件没有写入权限,所以首先需要运行命令:
sudo chmod -R 777 profile
这里需要输入密码kivydev
,当然输入的密码是隐形,千万不要以为没有输进去。
然后就可以写入下面到profile文件末尾,因为本虚拟机jdk安装在java-8-openjdk-i386
#Java Env
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
python -3 -m pip install XXXX
之前打包时一直没有深入研究buildozer.spec,当结果在出现打包调用Android api的apk时一直出现闪退的情况。最后发现一下两点原因:
一直没有注意到requirements这一项,当加上python2后,打包的apk就没有出现闪退的情况,所以我以为这应该是打包apk的python程序需要的库。
有些示例程序打包的时候出现卡住完全不动的情况,后来发现这些示例程序buildozer.spec文件的log_level=1,当修改为log_level=2则打包可正常运行。
/etc/udev/rules.d/51-android.rules
文件(如果没有51-android.rules文件可自行新建),根据手机USB配置添加以下内容:SUBSYSTEM=="usb", ATTRS{idVendor}=="12D1", ATTRS{idProduct}=="107E",MODE="0666"
ATTRS{idVendor}=="12D1", ATTRS{idProduct}=="107E"
两项根据自己手机修改,"12D1"
和"107E"
怎样获取参见下图:
3.配置完成后,执行以下命令使得配置生效(建议直接重启)。
sudo chmod a+rx /etc/udev/rules.d/51-android.rules
sudo service udev restart
sudo adb kill-server
sudo adb start-server
sudo devices
详情参见:https://www.jianshu.com/p/482cc488108d
1.在buildozer.spec文件中source.include_exts项添加ttf:
# //(list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,ttf
2.在main.py文件同目录下添加DroidSansFallback.ttf
文件,网上到处都有。
3.编辑main.py文件加入下面代码:
from kivy.core.text import LabelBase
LabelBase.register('Roboto', 'DroidSansFallback.ttf')
注:python的默认编码文件是用的ASCII码,而你的python文件中使用了中文等非英文字符。解决办法:在Python源文件的最开始一行,加入一句:#coding=UTF-8
(等号换为“:”也可以)或者#-- coding:UTF-8 --
注:python2.x的默认编码是ascii,而代码中可能由utf-8的字符导致,解决方法是设置utf-8,在开头添加如下代码:
import sys
reload(sys)
sys.setdefaultencoding('utf8')
1.首先参见“虚拟机USB连接手机”连接好手机,然后找到“开发人员选项”,打开USB调试选项。不同手机开发人员选项打开方式不同,可自行百度,以华为手机为例,“设置”中找到“关于手机”,反复点击版本号这一项即可。
2.虚拟机中输入命令(如果安装有adb的话也可以在Window上调用adb logcat | grep python
):
buildozer android logcat | grep python
链接: https://pan.baidu.com/s/1NGIgQhiU0CpjjzsIOd2K7Q
提取码: iujc
1.解压到/home/kivydev/pycharm/
2.添加-javaagent:/home/kivydev/pycharm/pycharm-2018.1.2/bin/JetbrainsCrack.jar
到 vim pycharm.vmoptions 和vim pycharm64.vmoptions 文件末尾
3.创建快捷方式,命令行输入sudo gedit /usr/share/applications/pycharm.desktop
,密码kivydev
,在文件中输入下面内容保存
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm
Comment=Pycharm:The Python IDE
Exec="/home/kivydev/pycharm/pycharm-2018.1.2/bin/pycharm.sh" %f
Icon=/home/kivydev/pycharm/pycharm-2018.1.2/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm;
4.Active code粘贴下面内容
T35KU9QVZ6-eyJsaWNlbnNlSWQiOiJUMzVLVTlRVlo2IiwibGljZW5zZWVOYW1lIjoi5YWs5LyX5Y+377yaIOeMv+afkOafkCIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzd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L9IF5n3wJOgkPojMy6jetQA5Ogc8Sm7RG6vg1yow==
5.如果虚拟机变得有点卡,参考https://blog.csdn.net/ass121/article/details/82561541修改虚拟机配置。其次我自己加了一条,在设置/系统/主板中还可以将内存大小适当调大一些:
6.全屏切换问题
切换到全屏模式:Ctrl + F
切换到无缝模式:Ctrl + L
切换到比例模式:Ctrl + C
显示控制菜单 :Ctrl + Home
注意:一定是右边的 Ctrl
当安装bs4时编译时没报错,但是手机上运行却报错No module named ‘bs4’,最后仔细观察编译下载bs4包时发现此处If this fails with a message about /bin/false, this probably means the package cannot be installed with pip as it needs a compilation recipe.
报错running bash -c source venv/bin/activate && env CC=/bin/false CXX=/bin/false
但没有编译失败,网上有一种解释为:
“根据此链接,只能自动安装纯python软件包,所有依赖于二进制编译的软件包都必须编写配方。配方是一个脚本,其中包含要编译的模块的“定义”。配方的目录布局类似于:”
python-for-android / recipes / recipe.sh
python-for-android / recipes / patches /
python-for-android / recipes / patches / fix-path.patch//构建时,所有配方构建必须转到:
python-for-android / build //例如,如果要为sdl创建配方,请执行以下操作:
cd python-for-android / recipes mkdir sdl cp recipe.sh.tmpl
sdl / recipe.sh sed -i's#XXX#sdl#'sdl / recipe.sh//然后,编辑
sdl / recipe.sh//调整其他信息(版本,URL)并完成构建功能。
我个人理解是在/home/kivydev/kivy/accordion/.buildozer/android/platform/python-for-android/recipes
目录下新建文件夹/bs4
然后找到/home/kivydev/kivy/accordion/.buildozer/android/platform/python-for-android/recipes/recipe.sh.tmpl
复制一份到/bs4
重命名为recipe.sh
,最将recipe.sh
文件中的xxx
全部替换成bs4
加上:
ScrollView:
GridLayout:
size_hint_y: None
height: self.minimum_height
就可以滑动了
参见:https://blog.csdn.net/qq_33974741/article/details/84229471
连接:https://github.com/kivy/plyer/tree/master/examples
连接:https://github.com/kivy/kivy/tree/master/examples