#python #android #kivy #virtual-machine #buildozer
Вопрос:
Я пытаюсь развернуть приложение для селфи-камеры Kivy на устройстве Android, и я получил это сообщение на терминале в цикле
#waiting for the application to start
Я удостоверяюсь, что устройство подключено и режим разработчика уже активирован .так как же решить эту проблему ???
Ответ №1:
Я создал приложение для камеры hello world с использованием xcamera.
с помощью этого вы можете сохранить изображение, но оно будет находиться только в пределах области действия частного режиссера приложения. К которому нельзя получить доступ, если у вас нет корневого доступа. Чтобы сохранить его в общей памяти телефона, вы можете следовать этому примеру, нажав здесь
main.py
from kivy.clock import Clock
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy_garden.xcamera import XCamera
from android.permissions import request_permissions, Permission
#from storage import SharedStorage
try:
request_permissions([Permission.INTERNET,
Permission.READ_EXTERNAL_STORAGE,
Permission.WRITE_EXTERNAL_STORAGE,
Permission.CAMERA])
except Exception as e:
print("Like it's gonna work after this ! XD")
print(e)
KV = """
#:import XCamera kivy_garden.xcamera.XCamera
BoxLayout:
orientation: 'vertical'
BoxLayout:
id: camera_layout
canvas.before:
PushMatrix
Rotate:
angle: -90
origin: self.center
canvas.after:
PopMatrix
XCamera:
id: camera
"""
class uiApp(MDApp):
def shoot(self):
print("picture taken")
#SharedStorage().insert(path local_filename, 'Downloads')
print("End here")
def my_callback(self, dt):
print("Taking picture...")
self.screen.ids["camera"].shoot()
print("exit my_callback !")
def build(self):
self.screen = Builder.load_string(KV)
self.screen.ids["camera"].shoot = self.shoot
self.event = Clock.schedule_once(self.my_callback, 5)
return self.screen
uiApp().run()
Ознакомьтесь с требованиями и убедитесь, что они у вас установлены
Чтобы узнать, что все установлено на вашем локальном компьютере, используйте pip list
buildozer.спецификация
[app]
# (str) Title of your application
title = Hello_testcamera
# (str) Package name
package.name = Testcam
# (str) Package domain (needed for android/ios packaging)
package.domain = org.test.cam
# (str) Source code where the main.py live
source.dir = .
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,json,xlsx,pdf,crt,pem,cer,ttf,json
# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png
# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec
# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin
# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
version = 0.35
requirements = xcamera,hostpython3==3.7.9,python3==3.7.9,kivy==2.0.0,kivymd==0.104.1,dateutil,urllib3,jmespath,jnius,cython,android,opencv-python,android,pillow,plyer,requests,chardet,idna
orientation = all
# (list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
#
# OSX Specific
#
#
# author = © Copyright Info
# change the major version of python used by the app
osx.python_version = 3
# Kivy version to use
osx.kivy_version = 1.9.1
#
# Android specific
#
# (bool) Indicate if the application should be fullscreen or not
fullscreen = 1
#android.presplash_color = #FFFFFF
# (list) Permissions
android.permissions = INTERNET,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE,CAMERA
# (int) Target Android API, should be as high as possible.
android.api = 29
# (int) Minimum API your APK will support.
#android.minapi = 27
# (int) Android SDK version to use
#android.sdk = 21
# (str) Android NDK version to use
#android.ndk = 19c
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
#android.ndk_api = 21
android.accept_sdk_license = True
# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
android.arch = arm64-v8a