kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.61k stars 427 forks source link

Notification.notify crashes android app #296

Closed Fogapod closed 7 years ago

Fogapod commented 7 years ago

I created my kivy app using android_new buildozer toolchain. (It works fine on old android toolchain) My app get crashed when plyer's notification.notify() is called. There is no exception. So I can't catch it.

sumitmadhwani commented 7 years ago

Hi @Fogapod , can you please share the logs which are generated when you run your app?

Fogapod commented 7 years ago

@malverick , unfortunantely, there's nothing useful in kivy logs:

[INFO   ] Logger: Record log in /data/user/0/org.vkbot_testing/files/app/.kivy/logs/kivy_17-03-11_1.txt
[INFO   ] Kivy: v1.9.2.dev0, git-Unknown, 20170311
[INFO   ] Python: v2.7.2 (default, Mar 10 2017, 17:52:09) 
[GCC 4.8]
[INFO   ] Factory: 194 symbols loaded
[DEBUG  ] Cache: register <kv.lang> with limit=None, timeout=None
[DEBUG  ] Cache: register <kv.image> with limit=None, timeout=60
[DEBUG  ] Cache: register <kv.atlas> with limit=None, timeout=None
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[DEBUG  ] Cache: register <kv.texture> with limit=1000, timeout=60
[DEBUG  ] Cache: register <kv.shader> with limit=1000, timeout=3600
[INFO   ] OSC: using <thread> for socket
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL ES 2" graphics system
[DEBUG  ] GL: glShaderBinary is not available
[INFO   ] GL: Backend used <gl>
[INFO   ] GL: OpenGL version <OpenGL ES 3.0 V@140.0 AU@ (GIT@I741a3d36ca)>
[INFO   ] GL: OpenGL vendor <Qualcomm>
[INFO   ] GL: OpenGL renderer <Adreno (TM) 330>
[INFO   ] GL: OpenGL parsed version: 3, 0
[INFO   ] GL: Texture max size <4096>
[INFO   ] GL: Texture max units <16>
[DEBUG  ] Shader: Fragment compiled successfully
[DEBUG  ] Shader: Vertex compiled successfully
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/glsl/default.png>
[INFO   ] Window: auto add sdl2 input provider
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[DEBUG  ] App: Loading configuration </sdcard/.chatbot.ini>
[DEBUG  ] App: Loading kv </data/user/0/org.vkbot_testing/files/app/chatbot.kv>
[WARNING] Factory: Ignored class "Screen" re-declaration. Current -  module: kivy.uix.screenmanager, cls: None, baseclass: None, filename: None. Ignored -  module: None, cls: None, baseclass: Screen, filename: /data/user/0/org.vkbot_testing/files/app/chatbot.kv.
[WARNING] Factory: Ignored class "TextInput" re-declaration. Current -  module: kivy.uix.textinput, cls: None, baseclass: None, filename: None. Ignored -  module: None, cls: None, baseclass: TextInput, filename: /data/user/0/org.vkbot_testing/files/app/chatbot.kv.
[DEBUG  ] ImageSDL2: Load </data/data/org.vkbot_testing/files/app/data/images/background.jpg>
[INFO   ] GL: NPOT texture support is available
[INFO   ] Text: Provider: sdl2
[DEBUG  ] Atlas: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme.atlas>
[DEBUG  ] Atlas: Need to load 1 images
[DEBUG  ] Atlas: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme-0.png>
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme-0.png>
[DEBUG  ] Resource: add </system/fonts> in path list
[DEBUG  ] Resource: add </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/fonts> in path list
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/logo/kivy-icon-32.png>
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot_testing/files/app/lib/python2.7/site-packages/kivy/data/logo/kivy-icon-32.png>
[DEBUG  ] Cache: register <textinput.label> with limit=None, timeout=60.0
[DEBUG  ] Cache: register <textinput.width> with limit=None, timeout=60.0
[DEBUG  ] Base: Create provider from android
[WARNING] Base: Unknown <android> provider
[INFO   ] Base: Start application main loop
[ERROR  ] Base: Failed to import "android" module. Could not remove android presplash.

Also I can't debug my apk after building (I'm using virtual machine with buildozer and have some problems connecting my device to it)

Maybe I can send you apk file for testing?

Fogapod commented 7 years ago

If so, my_apk_file_here.zip _20170311_145524 Pressing this button should call notification.notify(title='title', message='message') (working great on android toolchain, but not on android_new)

sumitmadhwani commented 7 years ago

hi @Fogapod , I tested your app and here are the logs logs.txt

After doing some research I found that this is a bug in new toolchain. http://stackoverflow.com/questions/41156449/python-kivy-with-plyer-app-crashes-on-android-camera

Try adding android in requirements section in your buildozer.spec file. @inclement can help you more over this.

kuzeyron commented 7 years ago

When I was trying the "android_new" I had to listen through: adb bugreport > bugreport.txt

Fogapod commented 7 years ago

@malverick, including android to the requirements didn't help. Kivy logs:

[INFO   ] Logger: Record log in /data/user/0/org.vkbot/files/app/.kivy/logs/kivy_17-03-12_3.txt
[INFO   ] Kivy: v1.9.2.dev0, git-Unknown, 20170310
[INFO   ] Python: v2.7.2 (default, Mar 10 2017, 17:52:09) 
[GCC 4.8]
[INFO   ] Factory: 194 symbols loaded
[DEBUG  ] Cache: register <kv.lang> with limit=None, timeout=None
[DEBUG  ] Cache: register <kv.image> with limit=None, timeout=60
[DEBUG  ] Cache: register <kv.atlas> with limit=None, timeout=None
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[DEBUG  ] Cache: register <kv.texture> with limit=1000, timeout=60
[DEBUG  ] Cache: register <kv.shader> with limit=1000, timeout=3600
[INFO   ] OSC: using <thread> for socket
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL ES 2" graphics system
[DEBUG  ] GL: glShaderBinary is not available
[INFO   ] GL: Backend used <gl>
[INFO   ] GL: OpenGL version <OpenGL ES 3.0 V@140.0 AU@ (GIT@I741a3d36ca)>
[INFO   ] GL: OpenGL vendor <Qualcomm>
[INFO   ] GL: OpenGL renderer <Adreno (TM) 330>
[INFO   ] GL: OpenGL parsed version: 3, 0
[INFO   ] GL: Texture max size <4096>
[INFO   ] GL: Texture max units <16>
[DEBUG  ] Shader: Fragment compiled successfully
[DEBUG  ] Shader: Vertex compiled successfully
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/glsl/default.png>
[INFO   ] Window: auto add sdl2 input provider
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[DEBUG  ] App: Loading configuration </sdcard/.chatbot.ini>
[DEBUG  ] App: Loading kv </data/user/0/org.vkbot/files/app/chatbot.kv>
[WARNING] Factory: Ignored class "Screen" re-declaration. Current -  module: kivy.uix.screenmanager, cls: None, baseclass: None, filename: None. Ignored -  module: None, cls: None, baseclass: Screen, filename: /data/user/0/org.vkbot/files/app/chatbot.kv.
[WARNING] Factory: Ignored class "TextInput" re-declaration. Current -  module: kivy.uix.textinput, cls: None, baseclass: None, filename: None. Ignored -  module: None, cls: None, baseclass: TextInput, filename: /data/user/0/org.vkbot/files/app/chatbot.kv.
[DEBUG  ] ImageSDL2: Load </data/data/org.vkbot/files/app/data/images/background.jpg>
[INFO   ] GL: NPOT texture support is available
[INFO   ] Text: Provider: sdl2
[DEBUG  ] Atlas: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme.atlas>
[DEBUG  ] Atlas: Need to load 1 images
[DEBUG  ] Atlas: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme-0.png>
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/images/defaulttheme-0.png>
[DEBUG  ] Resource: add </system/fonts> in path list
[DEBUG  ] Resource: add </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/fonts> in path list
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/logo/kivy-icon-32.png>
[DEBUG  ] ImageSDL2: Load </data/user/0/org.vkbot/files/app/lib/python2.7/site-packages/kivy/data/logo/kivy-icon-32.png>
[DEBUG  ] Cache: register <textinput.label> with limit=None, timeout=60.0
[DEBUG  ] Cache: register <textinput.width> with limit=None, timeout=60.0
[DEBUG  ] Base: Create provider from android
[WARNING] Base: Unknown <android> provider
[INFO   ] Base: Start application main loop
ZingBallyhoo commented 7 years ago

Here is the actual log from the supplied apk, without the logcat filter on: https://gist.github.com/ZingBallyhoo/f3c1bc308bb20a5ff43da94061f39f0c

The most important part of this is: PythonActivity: Accessing org.renpy.android.PythonActivity is deprecated and will be removed in a future version. Please switch to org.kivy.android.PythonActivity.

The issue should be fixed if the android module is properly installed (see https://github.com/kivy/plyer/blob/master/plyer/platforms/android/__init__.py#L8)

@Fogapod can you send me your apk with the android module, so I can see if there is a deeper issue.

Fogapod commented 7 years ago

@ZingBallyhoo archive.zip

main.py:

from kivy.app import App
from kivy.uix.button import Button

from plyer import notification

import android # no ImportError here

class MyApp(App):
    def build(self):
        return Button(text='notificate', on_press=self.noti)

    def noti(self, *args):
        notification.notify(title='title', message='message')

if __name__ == '__main__':
    MyApp().run()
ZingBallyhoo commented 7 years ago

@Fogapod Any chance you can rebuild and send me the APK again after you make some changes?

I can see where the issue is, but the exception is silenced by a try: except: pass block

Fogapod commented 7 years ago

Here it is: archive.zip

Nothing new in kivy logs

ZingBallyhoo commented 7 years ago

Found the problem, your APK is using an old version of Plyer, before the android_new support.

org.renpy.android.PythonActivity was hardcoded back then, and is deprecated now, hence the error.

What you need to do:

Then, it should work

Fogapod commented 7 years ago

But I used master branch of plyer in my first app that I posted here and it didn't work no matter including or excluding android from requirements, I also tried deleting .buildozer folder several times. I'll try to check that again tomorrow.

ZingBallyhoo commented 7 years ago

@Fogapod I just had a dig around in your original APK's assets, and it is not using plyer from master. Having plyer as a requirement does not use the latest version from github, it uses the latest release on PyPI, which is outdated.

You need to do a clean rebuild to use the latest Plyer (after updating the requirements)

This is the file that I found in your APK, which causes the bug:


from os import environ
from jnius import autoclass
ANDROID_VERSION = autoclass('android.os.Build$VERSION')
SDK_INT = ANDROID_VERSION.SDK_INT
if 'PYTHON_SERVICE_ARGUMENT' in environ:
    PythonService = autoclass('org.renpy.android.PythonService')
    activity = PythonService.mService
else:
    PythonActivity = autoclass('org.renpy.android.PythonActivity')
    activity = PythonActivity.mActivity``` 
Fogapod commented 7 years ago

I put plyer directly into my app folder, not using requirements: importing from lib; Here is this folder, isn't it master?

ZingBallyhoo commented 7 years ago

@Fogapod Well, the APK you gave us has from plyer import notification, and doesn't even have a libs folder, and yes, the new libs folder does have Plyer from master.

Can you please build the latest version of that app and send it (if it still doesn't work)

Fogapod commented 7 years ago

@ZingBallyhoo ok, that's very weired. I'll build new apk tomorrow. Thanks for your help

Fogapod commented 7 years ago

I created 2 apk's: android_excluded.zip android_included.zip

Now both of them are raising NotImplementedError: No usable implementation found!

Edit: I created third apk including plyer master branch in requirements. It's working fine now. The problem should be in my code. Sorry for wasting your time. Closing issue.

nancygeorge1997 commented 4 years ago

i had the same issue in my speech to text application and i tried all the solutions in the comment but it didnt work , is there a chance anyone can help here are the logs before and after errors after solving.txt errors before solving.txt

pavankoushal commented 4 years ago

i have created a kivy app in which we can get list of applications in our mobile and we can uninstall apps from my kivy app.it is working good in pc but, when i install it my mobile it is displaying the list of applications but when i press the delete button of respective app, kivy app is crashing. i had also gone through the logcat . it is showing an error "subprocess.CalledProcessError"

for example i want to delete truecaller app through my kivy app .so when i press the delete button of true caller in kivy app it is showing an error in logact i.e " subprocess.CalledProcessError: Command 'pm uninstall -k --user 0 com.truecaller ' returned non-zero exit status 255. " can anybody know what is the error here? or is there any changes i have to do in my buildozer.spec file ?

pls help me to solve this issue

inclement commented 4 years ago

Do you have some documentation indicating that calling pm as a subprocess from your app should work? My immediate guess would be that this simply isn't allowed.

On 20/08/2020 19:05, pavankoushal wrote:

i have created a kivy app in which we can get list of applications in our mobile and we can uninstall apps from my kivy app.it is working good in pc but, when i install it my mobile it is displaying the list of applications but when i press the delete button of respective app, kivy app is crashing. i had also gone through the logcat . it is showing an error "subprocess.CalledProcessError"

for example i want to delete truecaller app through my kivy app .so when i press the delete button of true caller in kivy app it is showing an error in logact i.e " subprocess.CalledProcessError: Command 'pm uninstall -k --user 0 com.truecaller ' returned non-zero exit status 255. " can anybody know what is the error here? or is there any changes i have to do in my buildozer.spec file ?

pls help me to solve this issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kivy/plyer/issues/296#issuecomment-677816411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVBGZ3SDL76GPBXU3P6RDSBVQYFANCNFSM4DC7CW6Q.