Plyer makecall kills my Kivy App on GNU/Linux and Android

196 views
Skip to first unread message

Ghiom

unread,
Dec 3, 2020, 5:29:10 AM12/3/20
to Kivy users support

Hi all,


I'm making a Python3/Kivy application for Android/iOS using Buildozer.


It scraps informations from a website with beautifulsoup4 (with a workaround to bypass an error with htmlparser) and show them on screen with Kivy. I also add 4 buttons, 3 for social media purpose (with webbrowser) and one to give a phone number to the mobile phone module (with Plyer).


For that part with Plyer, I'm defining phonecall() who use the call.makecall(tel='number') method. That doesn't work at all and my application crashes on GNU/Linux or Android when I try to add that button bind. Here the message I get on GNU/Linux (you can check my logs for the Android one).


   File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/utils.py", line 93, in _ensure_obj
     mod
= __import__(module, fromlist='.')
 
ModuleNotFoundError: No module named 'plyer.platforms'
 
Traceback (most recent call last):
   
File "main.py", line 194, in <module>
     
ConceptruelleApp().run()
   
File "/usr/lib/python3/dist-packages/kivy/app.py", line 800, in run
     root
= self.build()
   
File "main.py", line 133, in build
     btn1
.bind(on_press=phonecall(tel))
   
File "main.py", line 97, in phonecall
     call
.makecall(tel=tel)
   
File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/facades/call.py", line 45, in makecall
     
self._makecall(tel=tel)
   
File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/facades/call.py", line 56, in _makecall
     
raise NotImplementedError()
 
NotImplementedError

Plyers is imported, installed and specified on Buildozer for the Android version (buildozer.spec attached). I checked the files on my computer and I can find /home/guillaume/.local/lib/python3.8/site-packages/plyer/platforms/ with Android, iOS, Linux, MacOSX and Win folders inside.


If I comment the btn1.bind() line, my App works perfectly.


Can you help me please ?

buildozer.spec
_htmlparser.py
log.txt
main.py

Andreas Ecker

unread,
Dec 3, 2020, 6:13:03 AM12/3/20
to kivy-...@googlegroups.com
A kwarg of the `Widget.bind` method expepts a callable, which will be executed when the button gets pressed. But in your code you bind the `on_press` event to the return value of your `phonecall` function. So for to fix this change the following code line - instead of:

`btn1.bind(on_press=phonecall(tel))`

... you should put only the function name without the brackets and the argument:

btn1.bind(on_press=phonecall)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/08488fb3-4f11-4fdf-b743-3b21338a2a11o%40googlegroups.com.

Ghiom

unread,
Dec 3, 2020, 6:24:12 AM12/3/20
to Kivy users support
Thanks for your fast answer !

I did that and now the application run, but crashes (on Android or GNU\Linux) when I press the button.

Still the same error :

 Traceback (most recent call last):
   
File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/utils.py", line 93, in _ensure_obj
     mod
= __import__(module, fromlist='.')
 
ModuleNotFoundError: No module named 'plyer.platforms'
[INFO   ] [Base        ] Leaving application in progress...

 
Traceback (most recent call last):
   
File "main.py", line 194, in <module>
     
ConceptruelleApp().run()

   
File "/usr/lib/python3/dist-packages/kivy/app.py", line 826, in run
     runTouchApp
()
   
File "/usr/lib/python3/dist-packages/kivy/base.py", line 502, in runTouchApp
     
EventLoop.window.mainloop()
   
File "/usr/lib/python3/dist-packages/kivy/core/window/window_sdl2.py", line 727, in mainloop
     
self._mainloop()
   
File "/usr/lib/python3/dist-packages/kivy/core/window/window_sdl2.py", line 460, in _mainloop
     
EventLoop.idle()
   
File "/usr/lib/python3/dist-packages/kivy/base.py", line 340, in idle
     
self.dispatch_input()
   
File "/usr/lib/python3/dist-packages/kivy/base.py", line 325, in dispatch_input
     post_dispatch_input
(*pop(0))
   
File "/usr/lib/python3/dist-packages/kivy/base.py", line 231, in post_dispatch_input
     listener
.dispatch('on_motion', etype, me)
   
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   
File "/usr/lib/python3/dist-packages/kivy/core/window/__init__.py", line 1360, in on_motion
     
self.dispatch('on_touch_down', me)
   
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   
File "/usr/lib/python3/dist-packages/kivy/core/window/__init__.py", line 1376, in on_touch_down
     
if w.dispatch('on_touch_down', touch):
   
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   
File "/usr/lib/python3/dist-packages/kivy/uix/widget.py", line 460, in on_touch_down
     
if child.dispatch('on_touch_down', touch):
   
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   
File "/usr/lib/python3/dist-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
     
self.dispatch('on_press')
   
File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
   
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
   
File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
   
File "main.py", line 98, in phonecall
     call
.makecall(tel=tel)

   
File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/facades/call.py", line 45, in makecall
     
self._makecall(tel=tel)
   
File "/home/guillaume/.local/lib/python3.8/site-packages/plyer/facades/call.py", line 56, in _makecall
     
raise NotImplementedError()
 
NotImplementedError

Le jeudi 3 décembre 2020 12:13:03 UTC+1, Andreas Ecker a écrit :
A kwarg of the `Widget.bind` method expepts a callable, which will be executed when the button gets pressed. But in your code you bind the `on_press` event to the return value of your `phonecall` function. So for to fix this change the following code line - instead of:

`btn1.bind(on_press=phonecall(tel))`

... you should put only the function name without the brackets and the argument:

btn1.bind(on_press=phonecall)

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Andreas Ecker

unread,
Dec 3, 2020, 9:41:24 AM12/3/20
to kivy-...@googlegroups.com
The traceback you show in your last post is from a linux system, but plyer's `makecall` is only available on android and ios (see the table in the readme at https://github.com/kivy/plyer). So this crash is coming from the fact that there is no `makecall+  implementation for a linux OS, but on Android this should actually work.

Please use adb logcat for to get the crash traceback from your android system and post it here for to get further help.

happy coding/debugging



To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d52b4c98-377a-4b35-821e-94dd15b29c55o%40googlegroups.com.

Ghiom

unread,
Dec 3, 2020, 11:04:53 AM12/3/20
to Kivy users support
Hey ! Thanks again for your help. My new logs are attached with this message.

The error seems to be the same as my first logs, _makecall raising a NotImplementedError (that seems to be is job) :

12-03 17:00:46.478 14459 14561 I python  :    File "/home/guillaume/Documents/Python/ConcepTruelle_3/.buildozer/android/app/main.py", line 98, in phonecall
12-03 17:00:46.480 14459 14561 I python  :    File "/home/guillaume/Documents/Python/ConcepTruelle_3/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/conceptruelle/plyer/facades/call.py", line 45, in makecall
12-03 17:00:46.483 14459 14561 I python  :    File "/home/guillaume/Documents/Python/ConcepTruelle_3/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/conceptruelle/plyer/facades/call.py", line 56, in _makecall
12-03 17:00:46.485 14459 14561 I python  :  NotImplementedError
12-03 17:00:46.485 14459 14561 I python  : Python for android ended.


log.txt

Andreas Ecker

unread,
Dec 3, 2020, 11:46:48 AM12/3/20
to kivy-...@googlegroups.com
Sad to hear that you got the same error on android...

As next you could try the master branch of plyer (putting plyer==master in the requirements setting of your buildozer.spec).

What also looks strange is that the paths in the traceback of your logcat output having the buildozer folder structure... sorry but I'm out of ideas now - hope that one of the kivy/plyer experts can help you out.....

fingers crossed



To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b94b3dfb-73ae-43cf-bfdd-dc4662c3cf22o%40googlegroups.com.

Ghiom

unread,
Dec 3, 2020, 11:53:13 AM12/3/20
to Kivy users support
The kivy==master doesn't change a thing :(

Thanks for your help anyway ! I add the new logs an cross fingers to :p
log.txt

Andreas Ecker

unread,
Dec 4, 2020, 9:23:38 AM12/4/20
to kivy-...@googlegroups.com
I actually recommended to use the master repository of plyer (not kivy)... if this is not helping then I'm out of ideas ...

unfortunately I never used plyers call module .. you could try to get support on the discord channel of kivy (https://chat.kivy.org)

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/adec134a-65b6-4c1f-ad10-9c4450fd4603o%40googlegroups.com.

planckp...@gmail.com

unread,
Dec 4, 2020, 12:06:20 PM12/4/20
to Kivy users support
Perhaps the extra import statement confuses plyer?  See the example

And looking ahead, read the Python webbrowser docs https://docs.python.org/3/library/webbrowser.html

Ghiom

unread,
Dec 5, 2020, 5:58:15 AM12/5/20
to Kivy users support
Sorry I'm actually using kivy==master that's why I wrote that, but my test was with plyer==master like you asked and it didn't work.
Thanks for your time and your help, I'll check that Discord Channel, I didn't know about it.

Le vendredi 4 décembre 2020 15:23:38 UTC+1, Andreas Ecker a écrit :
I actually recommended to use the master repository of plyer (not kivy)... if this is not helping then I'm out of ideas ...

unfortunately I never used plyers call module .. you could try to get support on the discord channel of kivy (https://chat.kivy.org)

Ghiom

unread,
Dec 5, 2020, 6:43:59 AM12/5/20
to Kivy users support
Hi and thanks for helping me :)

I added some motifications on my imports (file attached), but I still get the same error. I tryed to comment the _makecall definition on the call.py file, but still the same message and crash :(

Do you think that webbrowser could interact with plyer ? Cause the webbrowser binded buttons works well.

I use that part of the example code you shared with me, not on a special class, but inside my main class :

class MakeCallButton(Button):
    tel = StringProperty()

    def call(self, *args):
       call.makecall(tel=self.tel)
     


main.py

Ghiom

unread,
Dec 17, 2020, 9:13:56 AM12/17/20
to Kivy users support
Solved a part of the problem. Asking for permissions on the manifest is not enough, so I add those lines :

import android
from android.permissions import request_permissions, Permission
request_permissions
([Permission.CALL_PHONE])

I tryed a simple app, just un button who call with Plyer and it works.
On my main app, it's still not working so I continue to search where is the problem.

planckp...@gmail.com

unread,
Dec 17, 2020, 11:55:25 AM12/17/20
to Kivy users support
request_permissions() must be called in the build() method, else there will be unexpected behavior.

Ghiom

unread,
Dec 19, 2020, 1:15:54 AM12/19/20
to Kivy users support
Hi and thanks for the information. So I'll have to put the request in my main class ? Or starting my "if __name__ == '__main__':" ?
Sorry for the dumb question, but I'm new to coding and learn by my self :)

planckp...@gmail.com

unread,
Dec 19, 2020, 1:31:51 AM12/19/20
to Kivy users support
In the main class (inherited from App), you have a method named build. Put request_permissions() in there.

See the gray box that says build()

Teaching beginners is not really my thing.
If you have a basic programming with Kivy question, start a new thread and Elliot will probably respond.
He is really good at explaining.

Ghiom

unread,
Dec 19, 2020, 6:46:45 AM12/19/20
to Kivy users support
Thanks again ! I was thinking at first that the buildozer.spec would do all the permission work (it works for INTERNET so...), I'm learning step by step and your help is greatly appreciated !

planckp...@gmail.com

unread,
Dec 19, 2020, 11:27:36 AM12/19/20
to Kivy users support
on permissions: Android has evolved, there are two levels of permission.
First in the .spec which gives you "Manifest permission"
Second in the app, which gives you 'App permission".
App permission is only required if the permission is "dangerous" - see Android docs.

Its a learning curve.

Ghiom

unread,
Dec 22, 2020, 10:02:02 AM12/22/20
to Kivy users support
I've found the culprit and all is working well now. Plyer was not in cause, but the workaround for beautifulsoup created the problem.
Here the code :

class ImportFixer(object):
   
def __init__(self, mname):
       
self.mname = mname

   
def find_module(self, name, path=None):
       
if name == self.mname:
           
return self
       
return None

   
def load_module(self, name):
       
import _htmlparser as module
       
module.__name__ = name
       
return module

sys
.meta_path = [ImportFixer('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup

It's the last part that was causing a problem. the sys.meta_path was modified and not put back to his original state after that. So now I go with :

smp2 = sys.meta_path
sys
.meta_path = [ImportFixer('bs4.builder._htmlparser')]
from bs4 import BeautifulSoup

sys.meta_path = smp2

Perhaps it'll help someone someday !

Thanks again for all your kind help !
Reply all
Reply to author
Forward
0 new messages