【问题标题】:python kivy with plyer app crashes on android (camera)带有plyer应用程序的python kivy在android(相机)上崩溃
【发布时间】:2016-12-15 04:29:19
【问题描述】:

我使用 plyer 开发 kivy 应用程序。通过buildozer构建并在android上启动应用程序成功,但是当我按下启动相机的按钮时应用程序崩溃,并且logcat中没有任何输出。当我在 kivylauncher 中执行相同的代码时,我的工作没有问题。即使我用加速度计测试它也是相似的。

我认为当我使用 plyer 构建应用程序时,必要的设置可能会很短。

--- source code ---

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from plyer import camera

class UI(FloatLayout):
    def __init__(self, **kwargs):
        super(UI, self).__init__(**kwargs)
        self.lblCam = Label(text="Click to take a picture")
        self.add_widget(self.lblCam)

    def on_touch_down(self, e):
        try:
            print('test')
            camera.take_picture('/storage/sdcard0/example.jpg', self.done)
        except NotImplementedError:
            print("This feature has not yet been implemented for this platform")
        except Exception as e:
            print(str(type(e)))

    def done(self, e):
        self.lblCam.text = e

class Camera(App):
    def build(self):
        ui = UI()
        return ui

    def on_pause(self):
        return True

    def on_resume(self):
        pass

Camera().run()


 --- buildozer.spec ---
(buildozer android_new debug)

requirements = plyer,kivy,python2
android.permissions = CAMERA
android.api = 22
android.minapi = 21
android.sdk = 22
android.ndk = 13b
android.bootstrap = sdl2

--- environments
buildozer: 0.33dev
android (device)version: 5.0.2

--- adb logcat -s python ---
I/python  (30711): AND: Ran string
I/python  (30711): Run user program, change dir and execute entrypoint
I/python  (30711): [WARNING] [Config      ] Older configuration version detected (0 instead of 16)
I/python  (30711): [WARNING] [Config      ] Upgrading configuration in progress.
I/python  (30711): [INFO   ] [Logger      ] Record log in /data/data/org.test.cameraapp/files/app/.kivy/logs/kivy_16-12-15_0.txt
I/python  (30711): [INFO   ] [Kivy        ] v1.9.2-dev0
I/python  (30711): [INFO   ] [Python      ] v2.7.2 (default, Dec 15 2016, 13:03:19) 
I/python  (30711): [GCC 4.9.x 20150123 (prerelease)]
I/python  (30711): [INFO   ] [Factory     ] 193 symbols loaded
I/python  (30711): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
I/python  (30711): [INFO   ] [Text        ] Provider: sdl2
I/python  (30711): [INFO   ] [OSC         ] using <thread> for socket
I/python  (30711): [ERROR  ] [Input       ] AndroidJoystick is not supported by your version of linux
I/python  (30711): Traceback (most recent call last):
I/python  (30711):   File "/home/kivy/Documents/echizen-cyo/camera/.buildozer/android/platform/build/dists/cameraapp/private/lib/python2.7/site-packages/kivy/input/providers/__init__.py", line 57, in <module>
I/python  (30711):   File "/home/kivy/Documents/echizen-cyo/camera/.buildozer/android/platform/build/dists/cameraapp/private/lib/python2.7/site-packages/kivy/input/providers/androidjoystick.py", line 20, in <module>
I/python  (30711): Exception: android lib not found.
I/python  (30711): [INFO   ] [Window      ] Provider: sdl2
I/python  (30711): [INFO   ] [GL          ] OpenGL version <OpenGL ES 2.0>
I/python  (30711): [INFO   ] [GL          ] OpenGL vendor <ARM>
I/python  (30711): [INFO   ] [GL          ] OpenGL renderer <Mali-450 MP>
I/python  (30711): [INFO   ] [GL          ] OpenGL parsed version: 2, 0
I/python  (30711): [INFO   ] [GL          ] Texture max size <4096>
I/python  (30711): [INFO   ] [GL          ] Texture max units <8>
I/python  (30711): [INFO   ] [Window      ] auto add sdl2 input provider
I/python  (30711): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
I/python  (30711): [WARNING] [Base        ] Unknown <android> provider
I/python  (30711): [INFO   ] [Base        ] Start application main loop
I/python  (30711): [INFO   ] [GL          ] NPOT texture support is available
I/python  (30711): [ERROR  ] [Base        ] Could not remove android presplash
I/python  (30711): test

我担心“异常:找不到 android lib。”。

【问题讨论】:

    标签: android python kivy buildozer


    【解决方案1】:

    经过调查,我了解到它在 plyer.platform.android.init.py 中崩溃了。

    似乎在 activivity = PythonActivity.mActivity 中崩溃了,但无法处理异常。

    --- plyer.platform.android.__init__.py ---
    
    from os import environ
    from jnius import autoclass
    
    ANDROID_VERSION = autoclass('android.os.Build$VERSION')
    SDK_INT = ANDROID_VERSION.SDK_INT
    
    print('ANDROID_VERSION = {}'.format(SDK_INT))
    
    if 'PYTHON_SERVICE_ARGUMENT' in environ:
        print('test-1-1')
        PythonService = autoclass('org.renpy.android.PythonService')
        print('test-1-2')
        activity = PythonService.mService
        print('test-1-3')
    else:
        print('test-2-1')
        PythonActivity = autoclass('org.renpy.android.PythonActivity')
        print('test-2-2')
        activity = PythonActivity.mActivity
        print('test-2-3')
    
    
    --- logcat ---
    
    I/python  ( 9384): AND: Ran string
    I/python  ( 9384): Run user program, change dir and execute entrypoint
    I/python  ( 9384): [WARNING] [Config      ] Older configuration version detected (0 instead of 16)
    I/python  ( 9384): [WARNING] [Config      ] Upgrading configuration in progress.
    I/python  ( 9384): Purge log fired. Analysing...
    I/python  ( 9384): Purge finished!
    I/python  ( 9384): [INFO   ] [Logger      ] Record log in /data/data/org.test.cameraapp/files/app/.kivy/logs/kivy_16-12-16_0.txt
    I/python  ( 9384): [INFO   ] [Kivy        ] v1.9.2-dev0
    I/python  ( 9384): [INFO   ] [Python      ] v2.7.2 (default, Dec 16 2016, 19:14:20) 
    I/python  ( 9384): [GCC 4.9.x 20150123 (prerelease)]
    I/python  ( 9384): [INFO   ] [Factory     ] 193 symbols loaded
    I/python  ( 9384): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
    I/python  ( 9384): [INFO   ] [Text        ] Provider: sdl2
    I/python  ( 9384): [INFO   ] [OSC         ] using <thread> for socket
    I/python  ( 9384): [ERROR  ] [Input       ] AndroidJoystick is not supported by your version of linux
    I/python  ( 9384): Traceback (most recent call last):
    I/python  ( 9384):   File "/home/kivy/Documents/echizen-cyo/camera/.buildozer/android/platform/build/dists/cameraapp/private/lib/python2.7/site-packages/kivy/input/providers/__init__.py", line 57, in <module>
    I/python  ( 9384):   File "/home/kivy/Documents/echizen-cyo/camera/.buildozer/android/platform/build/dists/cameraapp/private/lib/python2.7/site-packages/kivy/input/providers/androidjoystick.py", line 20, in <module>
    I/python  ( 9384): Exception: android lib not found.
    I/python  ( 9384): [INFO   ] [Window      ] Provider: sdl2
    I/python  ( 9384): [INFO   ] [GL          ] OpenGL version <OpenGL ES   2.0>
    I/python  ( 9384): [INFO   ] [GL          ] OpenGL vendor <ARM>
    I/python  ( 9384): [INFO   ] [GL          ] OpenGL renderer <Mali-450 MP>
    I/python  ( 9384): [INFO   ] [GL          ] OpenGL parsed version: 2, 0
    I/python  ( 9384): [INFO   ] [GL          ] Texture max size <4096>
    I/python  ( 9384): [INFO   ] [GL          ] Texture max units <8>
    I/python  ( 9384): [INFO   ] [Window      ] auto add sdl2 input provider
    I/python  ( 9384): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
    I/python  ( 9384): [WARNING] [Base        ] Unknown <android> provider
    I/python  ( 9384): [INFO   ] [Base        ] Start application main loop
    I/python  ( 9384): [INFO   ] [GL          ] NPOT texture support is available
    I/python  ( 9384): [ERROR  ] [Base        ] Could not remove android presplash
    I/python  ( 9384): test
    I/python  ( 9384): ANDROID_VERSION = 21
    I/python  ( 9384): test-2-1
    I/python  ( 9384): test-2-2
    

    【讨论】:

      【解决方案2】:

      这是 p4a/pyjnius 中的 bug。在修复之前,您可以使用旧工具链。

      【讨论】:

      • 感谢您的回答。
      • @asaitoc 一点也不。我最近遇到了这个问题:github.com/kivy/python-for-android/issues/959 我发现最简单的方法是使用旧工具链。答案中的补丁对我没有帮助。
      • 相机使用旧工具链成功。但是,我在我的应用程序中使用了 spataiite,但是当我通过内置旧工具链的应用程序加载 mod_spatialite.so 时,出现了找不到符号的错误。但是我试过之后,我都很好并且紧张,因为新工具链中pyjnius补丁的应用方法在你的链接中列出。谢谢你的好建议!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 2016-08-23
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多