IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 移动端 开源低代码工具 beeware 和 kivy -> 正文阅读

[移动开发]移动端 开源低代码工具 beeware 和 kivy

移动端 开源低代码工具 beeware 和 kivy

kivy

kivy安装

#anaconda3 @ win10
python --version
#Python 3.8.5

pip install virtualenv
python -m virtualenv kivy_venv
#若virtualenv 报错, 试试:#conda create python=3.8 -n kivy_venv

kivy_venv\Scripts\activate.bat
##: conda activate kivy_venv

which pip
#/home/z//python_root/Miniconda3-4.10.3/envs/kivy_venv/bin/pip

pip install "kivy[dev]" kivy_examples
#dev, base, full 参见:   https://kivy.org/doc/stable/gettingstarted/installation.html  : "Installing Kivy’s dependencies"
#显示例子
python kivy_venv\share\kivy-examples\demo\showcase\main.py

kivy编译 出 android apk

#centos 8 x64 stream @"win10x64 hyperv"
/home/z/python_root/Miniconda3-4.10.3/bin/activate kivy_venv

#安装buildozer
cd /home/z/
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python setup.py install
#"安装buildozer" 这段可以用此替代:  pip install buildozer



cd /home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/pictures/
buildozer init

#安装buildozer所需依赖
#https://buildozer.readthedocs.io/en/latest/installation.html#targeting-android

export JAVA_HOME=/home/z/java_root/jdk-11.0.15+10/
export PATH=$JAVA_HOME/bin:$PATH

buildozer android release 

#成功编译出apk: 能在手机上正常运行.
#/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/pictures/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/dists/myapp/build/outputs/apk/debug/myapp-debug.apk  




"""

kivy编译报错解决 ( buildozer android release )

buildozer android release时报错: Cython (cython) not found, please install it

#centos 8 stream x64 @ "hyperv @win10x64"
buildzer android release
#报错: Cython (cython) not found, please install it
#解决:
#sudo dnf install python38-Cython.x86_64 -y  #这句可能不需要
pip install Cyton

which cython
#~/python_root/Miniconda3-4.10.3/envs/kivy_venv/bin/cython

编译python时, 报错 ctypes 找不到

编译python时, 报错 ctypes 找不到,

原因: 编译hostpython3时没有找到合适的libffi:

解决过程:

#报错:
"""
skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/8/../../../libffi.so when searching for -lffi
skipping incompatible //lib/libffi.so when searching for -lffi
skipping incompatible //usr/lib/libffi.so when searching for -lffi
cannot find -lffi
"""

ls -lh   /usr/lib64/libffi.so.*  #不兼容的so如下
"""
lrwxrwxrwx. 1 root root  26 Jul 27 10:11 /usr/lib/libffi.so -> /usr/lib64/libffi.so.6.0.2
lrwxrwxrwx. 1 root root  15 Jul 27 12:54 /usr/lib/libffi.so.6 -> libffi.so.6.0.2
-rwxr-xr-x. 1 root root 73K Jul 27 10:11 /usr/lib/libffi.so.6.0.2
"""

ls -lh   /usr/lib64/libffi.so.* #另一组so如下, (经过后面尝试发现, 这组是兼容的)
"""
lrwxrwxrwx. 1 root root  26 Jul 27 10:11 /usr/lib64/libffi.so.6 -> /usr/lib64/libffi.so.8.1.0
lrwxrwxrwx. 1 root root  15 Jul 27 12:54 /usr/lib64/libffi.so.8 -> libffi.so.8.1.0
-rwxr-xr-x. 1 root root 73K Jul 27 10:11 /usr/lib64/libffi.so.8.1.0
"""
#错误解决:
mkdir /tmp/usr_lib;  cp /usr/lib/libffi.so* /tmp/usr_lib#备份
unlink /usr/lib/libffi.so #删掉incompatible 的so
sudo ln -s    /usr/lib64/libffi.so.8.1.0  /usr/lib/libffi.so #指向好用的so
#单独编译看下效果: 正常编译了
gcc -pthread -shared build/temp.linux-x86_64-3.9/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/helloworld/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_ctypes/_ctypes.o build/temp.linux-x86_64-3.9/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/helloworld/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_ctypes/callbacks.o build/temp.linux-x86_64-3.9/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/helloworld/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_ctypes/callproc.o build/temp.linux-x86_64-3.9/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/helloworld/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_ctypes/cfield.o build/temp.linux-x86_64-3.9/home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/helloworld/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Modules/_ctypes/stgdict.o -L/usr/local/lib -lffi -ldl  -o build/lib.linux-x86_64-3.9/_ctypes.cpython-39-x86_64-linux-gnu.so

报错 不支持https

> buildozer android release   报错: Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/cython/: There was a problem confirming the ssl

>  原因是pip镜像站是https: https://pypi.tuna.tsinghua.edu.cn/simple
>  改为http的pip镜像站即可: http://mirrors.aliyun.com/pypi/simple/

#buildozer android release 继续报错
"""
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/cython/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/cython/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement Cython (from versions: none)
ERROR: No matching distribution found for Cython
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

beeware

#构建好py虚拟环境  
conda create python=3.8 -n beeware_venv
conda activate beeware_venv


pip install briefcase


android build

#set JAVA_HOME=D:\jdk1.8.0_111

#创建py项目:
briefcase new
#一路默认 novelz
#novelz/src/novelz/*.py
#如果要用pycharm 打开novelz/src/novelz/, 则应该安装:  pip install toga==v0.3.0.dev35


#刚刚创建py项目后, 将py转为android项目:
briefcase create android

#之后修改了py代码, 只需要更新android项目:
briefcase update android

#编译android项目为apk包
briefcase build android

 

 

beeware win10 手动激活conda环境

可以在cmd.exe下, 执行 D:\Miniconda3\Scripts\activate.bat , 激活base环境. 再执行conda activate beeware_venv 激活bee

#打开一个cmd窗口执性以下内容:
 D:\Miniconda3\Scripts\activate.bat 
 conda activate beeware_venv
 echo %PATH%
 #手工找出环境变量PATH中beeware_venv的部分, 这就是下面 git bash中手工激活beeware_venv的脚本

git bash 执行以下命令,手工激活 beeware_venv

beeware_env_path=/d/Miniconda3/envs/beeware_venv:/d/Miniconda3/envs/beeware_venv/Library/mingw-w64/bin:/d/Miniconda3/envs/beeware_venv/Library/usr/bin:/d/Miniconda3/envs/beeware_venv/Library/bin:/d/Miniconda3/envs/beeware_venv/Scripts:/d/Miniconda3/envs/beeware_venv/bin
export PATH=$PATH:$beeware_env_path

beeware create android 下载慢解决: github镜像、下载地址改本地

Python-3.8-Android-support.b5.zip 下载地址改为本地

briefcase create android

#create步会卡在下载  https://briefcase-support.org/python?platform=android&version=3.8
# 手工下载 放到路径  /home/z/beeware_demo/Python-3.8-Android-support.b5.zip

#修改 /home/z/python_root/Miniconda3-4.10.3/envs/beeware_venv/lib/python3.8/site-packages/briefcase/commands/create.py : install_app_support_package 函数
#将
#                support_package_url = app.support_package
#改成:
#                support_package_url = "/home/z/beeware_demo/Python-3.8-Android-support.b5.zip"
#再次运行briefcase create android可以通过

 

briefcase-android-gradle-template.git 改为镜像地址

#如果 它慢: "Using app template: https://github.com/beeware/briefcase-android-gradle-template.git, branch 3.8"
#修改  /home/z/python_root/Miniconda3-4.10.3/envs/beeware_venv/lib/python3.8/site-packages/briefcase/commands/create.py 
"""   @property
    def app_template_url(self):
        """The URL for a cookiecutter repository to use when creating apps."""
        #return f"https://github.com/beeware/briefcase-{self.platform}-{self.output_format}-template.git"
        #本行改成 github镜像加速地址:, 即可解决慢问题
        return f"https://github.91chi.fun//https://github.com/beeware/briefcase-{self.platform}-{self.output_format}-template.git"
"""

beeware build android 错误解决

centos8stream x64下beeware build android报错: libssl.so not recognized as a valid object file

briefcase build android
#运行中

#有以下报错: 
"""
/home/z/.briefcase/tools/android_sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip: error:
'/home/z/beeware_weather/weather/android/gradle/weather/app/build/intermediates/merged_native_libs/debug/out/lib/x86_64/libssl.so': The file was
not recognized as a valid object file

/home/z/.briefcase/tools/android_sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip: error:
'/home/z/beeware_weather/weather/android/gradle/weather/app/build/intermediates/merged_native_libs/debug/out/lib/x86_64/libcrypto.so': The file
was not recognized as a valid object file
"""
#解决
cd /home/z/beeware_wth/wth/android/gradle/wth/app/build/intermediates/merged_native_libs/debug/out/lib/armeabi-v7a/
unlink libcrypto.so
unlink libssl.so
ln -s `pwd`/libcrypto1.1.so  `pwd`/libcrypto.so
ln -s `pwd`/libssl1.1.so  `pwd`/libssl.so

win10下 beeware build android报错 : utf8 codec can’t decode byte 0xd3

python --version
#Python 3.8.13

briefcase --version
#0.3.8

briefcase build android

#报错详情
"""
> Task :app:compileDebugJavaWithJavac
Exception in thread D:\weather\android\gradle\weather\gradlew.bat output streamer:
Traceback (most recent call last):
  File "D:\Miniconda3\envs\beeware_venv\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "D:\Miniconda3\envs\beeware_venv\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Miniconda3\envs\beeware_venv\lib\site-packages\briefcase\integrations\subprocess.py", line 404, in _stream_output_thread
    print(popen_process.stdout.readline())
  File "D:\Miniconda3\envs\beeware_venv\lib\codecs.py", line 323, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 95: invalid continuation byte
"""

#解决办法:
export PYTHONIOENCODING=utf-8

beeware example

app.py

"""
A simple weather app.
"""
from pprint import pprint
import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW, LEFT, RIGHT
import httpx

TOKEN = "7eadee4312991c2935a8f9109645f19e" #Enter your weatherstack.com token here.
#http://api.weatherstack.com/current?access_key=7eadee4312991c2935a8f9109645f19e&query=New%20York
BASE_URL="http://api.weatherstack.com/current"

class weatherman(toga.App):

    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        main_box = toga.Box(style=Pack(direction=COLUMN))

        location_label = toga.Label("Location", style=Pack(padding=(0, 5)))
        self.location_input = toga.TextInput(style=Pack(flex=1))

        location_box = toga.Box(style=Pack(direction=ROW, padding=5))
        location_box.add(location_label)
        location_box.add(self.location_input)

        weather_box_label = toga.Label("Weather Results", style=Pack(padding=(0, 5)))
        self.weather_box_input = toga.TextInput(readonly=True, style=Pack(flex=1))
        weather_box = toga.Box(style=Pack(direction=ROW, padding=5))
        weather_box.add(weather_box_label)
        weather_box.add(self.weather_box_input)

        button = toga.Button("Fetch weather", on_press=self.weather, style=Pack(padding=5))

        main_box.add(location_box)
        main_box.add(button)
        main_box.add(weather_box)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

    def weather(self, widget):
        params = dict(access_key=TOKEN, query=self.location_input.value)
        resp = httpx.get(BASE_URL, params=params).json()
        try:
            self.weather_box_input.value = f'The weather report for  {resp["request"]["query"]} \
            {resp["current"]["temperature"]}  \
            {resp["current"]["weather_descriptions"][0]} \
            {resp["current"]["feelslike"]}'
        except ValueError:
            self.weather_box_input.value = "Location unknown!"



def main():
    return weatherman()

pyproject.toml

[tool.briefcase.app.wth]
formal_name = "wth"
description = "My first application"
icon = "src/wth/resources/wth"
sources = ['src/wth']
requires = [
'httpx~=0.23.0'  #这行是新增的, 因为app.py中用到了此库
]
cd /home/z/
mkdir /home/z/beeware_demo_wth
cd /home/z/beeware_demo_wth

briefcase new 
#应用名为:wth

cd /home/z/beeware_demo_wth/wth/

vi /home/z/beeware_demo_wth/wth/src/app.py
#替换为上面app.py的内容

briefcase create android
#注意慢问题, 参照上一节
#将会创建android项目结构 :/home/z/beeware_demo_wth/wth/android/

briefcase build android
#会报错 libcrypt.so, libssl.so找不到, 解决办法上一节已经写了. 这里复制来
cd /home/z/beeware_wth/wth/android/gradle/wth/app/build/intermediates/merged_native_libs/debug/out/lib/armeabi-v7a/
unlink libcrypto.so
unlink libssl.so
ln -s `pwd`/libcrypto1.1.so  `pwd`/libcrypto.so
ln -s `pwd`/libssl1.1.so  `pwd`/libssl.so


#再build一次即可
briefcase build android

#下载apk, 到手机上试一下:
/home/z/beeware_demo_wth/wth/android/gradle/wth/app/build/outputs/apk/debug/app-debug.apk
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-08-06 10:55:38  更:2022-08-06 10:59:11 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 4:35:01-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码