Buildozer: App crashes on android when using plyer camera

Created on 2 Jul 2017  路  9Comments  路  Source: kivy/buildozer

Hi all,

I am trying to build an apk package using buildozer. The app uses kivy plyer camera. The app starts normally on the phone and crashes when trying to access the camera. I couldn't find the exact cause, after some searching I realized that maybe it is related to the new python-for-android package. Below you can find the code.

main.py

from kivy.app import App #for the main app
from kivy.uix.floatlayout import FloatLayout #the UI layout
from kivy.uix.label import Label #a label to show information
from plyer import camera #object to read the camera

class UI(FloatLayout):#the app ui
    def __init__(self, **kwargs):
        super(UI, self).__init__(**kwargs)
        self.lblCam = Label(text="Click to take a picture!") #create a label at the center
        self.add_widget(self.lblCam) #add the label at the screen

    def  on_touch_down(self, e):
        camera.take_picture('/storage/sdcard0/example.jpg', self.done) #Take a picture and save at this location. After will call done() callback

    def done(self, e): #receive e as the image location
        self.lblCam.text = e; #update the label to the image location

class Camera(App): #our app
    def build(self):
        ui = UI()# create the UI
        return ui #show it

    def on_pause(self):
        #when the app open the camera, it will need to pause this script. So we need to enable the pause mode with this method
        return True

    def on_resume(self):
        #after close the camera, we need to resume our app.
        pass

Camera().run() #start our app


buildozer.spec:

[app]
title = Python Camera
package.name = camera
package.domain = com.wordpress.bytedebugger
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 1.3
requirements = python2,kivy, plyer
fullscreen = 1
android.permissions = CAMERA,WRITE_EXTERNAL_STORAGE
[buildozer]
log_level = 2

The app originally from:
http://blog.rhesoft.com/2014/07/19/python-for-android-tutorial-2-taking-a-picture/

All 9 comments

Adding "android" to the buildozer requirements worked for me... as I found out after hours of screwing around with plyer code.

Thanks for the note, maybe the plyer recipe should depend on the android module, although it's not strictly a hard dependency.

@benjamingeorgedanielryan adding "android" to the buildozer requirements --- do you mean in the buildozer.spec?

@Shamsyuhada Yes, add to the requirements list in the buildozer.spec alongside python2, kivy etc in the example above.

i have the same problem but put "android" on the requirements don't work.

I also have same problem, putting "android" in .spec file isn't working!!!! App crashes

This isn't a buildozer issue to me.
And @vyasdeep668 can't say anything without build log and run log

Is there any resolution to this ? I came here with the same problem. What do I need to provide to get some assistance ?

@codinghedgehog-python Please feel free to open a bug on the plyer repository, but it's unlikely anyone will pick it up soon. If you'd like help debugging it yourself, I suggest asking on the kivy discord channels.

Was this page helpful?
0 / 5 - 0 ratings