Pyjnius: 1.3.0 breaks android's request_permission

Created on 22 May 2020  路  23Comments  路  Source: kivy/pyjnius

reported by an user (Matrix0206 on discord).

from android import request_permission, Permission

request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
05-22 20:08:20.301 10976 11090 I python  :  Traceback (most recent call last):
05-22 20:08:20.301 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/app/main.py", line 300, in <module>
05-22 20:08:20.301 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/app.py", line 949, in run
05-22 20:08:20.302 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/app.py", line 919, in _run_prepare
05-22 20:08:20.302 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/app/main.py", line 132, in build
05-22 20:08:20.302 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/uix/relativelayout.py", line 274, in __init__
05-22 20:08:20.303 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/uix/floatlayout.py", line 65, in __init__
05-22 20:08:20.303 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/uix/layout.py", line 76, in __init__
05-22 20:08:20.303 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/uix/widget.py", line 359, in __init__
05-22 20:08:20.304 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/uix/widget.py", line 463, in apply_class_lang_rules
05-22 20:08:20.304 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/lang/builder.py", line 539, in apply
05-22 20:08:20.304 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/lang/builder.py", line 661, in _apply_rule
05-22 20:08:20.304 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/lang/builder.py", line 661, in _apply_rule
05-22 20:08:20.305 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/kivy/lang/builder.py", line 657, in _apply_rule
05-22 20:08:20.305 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/app/screens/main_screen/home.py", line 36, in __init__
05-22 20:08:20.305 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/android/permissions.py", line 570, in request_permissions
05-22 20:08:20.305 10976 11090 I python  :    File "/run/media/matrix/New_Volume/Developments/kivy-music-player/.buildozer/android/platform/build-arm64-v8a/build/python-installs/music_player/android/permissions.py", line 513, in request_permissions
05-22 20:08:20.306 10976 11090 I python  :    File "jnius/jnius_export_class.pxi", line 1134, in jnius.jnius.JavaMultipleMethod.__call__
05-22 20:08:20.306 10976 11090 I python  :  jnius.jnius.JavaException: No methods matching your arguments, requested: (['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.WRITE_EXTERNAL_STORAGE'],), available: []

while this worked in 1.2.1.

All 23 comments

hi guys I have the same problem, how to solve it? it's possible to use an older pyjnius in buildozer build? thanks!

hi guys I have the same problem, how to solve it? it's possible to use an older pyjnius in buildozer build? thanks!

Pinning the version using requirements = pyjnius==1.2.1,... should work.

I'm not a Kivy person, but can someone paste a link to the relevant source code?

hi guys I have the same problem, how to solve it? it's possible to use an older pyjnius in buildozer build? thanks!

Pinning the version using requirements = pyjnius==1.2.1,... should work.

thanks, infact it worked!

While pegging the Pyjnius version to 1.2.1 may work for this, v1.2.1 has other limitations, so ideally this should be addressed going forward....

Its made difficult as we cant easily see what the Activity class name is

i would expect it to be https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java#L42 but it can be the equivalent class in another bootstrap (https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/bootstraps)

It looks like python_activity.requestPermissions is a non-static method. But it's being called as if it were static. Which for some reason used to work with older versions of pyjnius. Using python_activity.mActivity.requestPermissions instead seems to work with 1.3.0.

So it looks like it's a bug in p4a's android library instead.

Good spot. Indeed; as in Java, calling a non-static method on a static object would not be allowed by the compiler. @obfusk can you update https://github.com/kivy/python-for-android/issues/2304?

I do think the Pyjnius error could be clearer also - ie the name of the method was not found and in what object!

I'm rather surprised this used to work. ~What instance was it being called on? A null pointer? Or some actual instance of the class?~

I do think the Pyjnius error could be clearer also - ie the name of the method was not found and in what object!

:+1:

I do think the Pyjnius error could be clearer also - ie the name of the method was not found and in what object!

馃憤

PR sent - see #558.

So the summary for anyone reading this in the future:

the patch has been merged

Not yet; but it has been approved :)

I think those FIXMEs are indeed related. Since __get__ sets the j_self instead of returning a bound method and simply returns self when called on a class instead of an instance, calling a non-static method on a class will use the last instance it was called on (if any). Of course, calling a non-static method on a class should never have been allowed (and no longer is).

I think those FIXMEs are indeed related. Since __get__ sets the j_self instead of returning a bound method and simply returns self when called on a class instead of an instance, calling a non-static method on a class will use the last instance it was called on (if any). Of course, calling a non-static method on a class should never have been allowed (and no longer is).

Can you show a simpler test case, and then we make a new issue?

Can you show a simpler test case, and then we make a new issue?

With 1.2.1:

>>> from jnius import autoclass
>>> s = autoclass("java.lang.String")
>>> s.toString()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "jnius/jnius_export_class.pxi", line 755, in jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 699, in jnius.JavaMethod.ensure_method
jnius.JavaException: Unable to find a None method!
classname: None, definition: ()Ljava/lang/String;
>>> s("foo").toString()
'foo'
>>> s.toString()
'foo'

With 1.3.0:

>>> from jnius import autoclass
>>> s = autoclass("java.lang.String")
>>> s("foo").toString()
'foo'
>>> s.toString()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "jnius/jnius_export_class.pxi", line 1134, in jnius.JavaMultipleMethod.__call__
jnius.JavaException: No methods matching your arguments, requested: (), available: []

Since calling a non-static method on a class no longer works, the problem's already been fixed.
And now we understand the cause of the problem.
So I don't think we need a new issue.

Or: as no-one seems aware of how this was fixed in 1.3.0, we add a testcase to prevent a future regression back to the previous behaviour. The testcase can expect the exception in the case above.

And can we remove the FIXME's then?

Or: as no-one seems aware of how this was fixed in 1.3.0, we add a testcase to prevent a future regression back to the previous behaviour. The testcase can expect the exception in the case above.

I've actually figured it out now. And the problem was only partially fixed :sweat_smile:. See #567

And can we remove the FIXME's then?

Not yet I think. See #563.

Just a note, I changed my p4a branch to 'develop' and still had this issue. I wiped my .buildozer folder and rebuilt, and the 'develop' branch won't build fresh for me without linking errors (2020-12-13, 16:22 -0500) (EDIT: sorry, this was a different issue. I can't seem to run buildozer successfully on my system, at all, for now.)

I think the way to go for working around this in client apps is to manually make the pyjnius call, so the client codebase will work equally well on the different versions. Obviously releases that fix this are sorely needed here.

Was this page helpful?
0 / 5 - 0 ratings