移动端 开源低代码工具 beeware 和 kivy
kivy
python --version
pip install virtualenv
python -m virtualenv kivy_venv
kivy_venv\Scripts\activate.bat
which pip
pip install "kivy[dev]" kivy_examples
python kivy_venv\share\kivy-examples\demo\showcase\main.py
/home/z/python_root/Miniconda3-4.10.3/bin/activate kivy_venv
cd /home/z/
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python setup.py install
cd /home/z/python_root/Miniconda3-4.10.3/envs/kivy_venv/share/kivy-examples/demo/pictures/
buildozer init
export JAVA_HOME=/home/z/java_root/jdk-11.0.15+10/
export PATH=$JAVA_HOME/bin:$PATH
buildozer android release
"""
kivy编译报错解决 ( buildozer android release )
buildozer android release时报错: Cython (cython) not found, please install it
buildzer android release
pip install Cyton
which 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.*
"""
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.*
"""
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
sudo ln -s /usr/lib64/libffi.so.8.1.0 /usr/lib/libffi.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/
"""
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
conda create python=3.8 -n beeware_venv
conda activate beeware_venv
pip install briefcase
android build
briefcase new
briefcase create android
briefcase update android
briefcase build android
beeware win10 手动激活conda环境
可以在cmd.exe下, 执行 D:\Miniconda3\Scripts\activate.bat , 激活base环境. 再执行conda activate beeware_venv 激活bee
D:\Miniconda3\Scripts\activate.bat
conda activate beeware_venv
echo %PATH%
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
briefcase-android-gradle-template.git 改为镜像地址
""" @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
briefcase --version
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"
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
cd /home/z/beeware_demo_wth/wth/
vi /home/z/beeware_demo_wth/wth/src/app.py
briefcase create android
briefcase build android
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
briefcase build android
/home/z/beeware_demo_wth/wth/android/gradle/wth/app/build/outputs/apk/debug/app-debug.apk
|