Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage' #702

Closed
tsiens opened this issue Nov 22, 2023 · 4 comments
Closed
Labels

Comments

@tsiens
Copy link

tsiens commented Nov 22, 2023

          Closing as the issue refers on a old version of `pyjnius`, and we do not support Python **2.7** anymore.

Feel free to re-open the issue if it persists on a recent pyjnius version (on a supported Python 3 version)

Originally posted by @misl6 in #608 (comment)

my environment

docker run -it  -e JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 -e ANDROIDSDK=/package/android-sdk -e ANDROIDNDK=/package/android-ndk-r25b -e ANDROIDAPI=33 -u root  -d ubuntu

apt update
apt install -y git zip unzip openjdk-17-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev automake
export PATH=$PATH:~/.local/bin/
pip install python-for-android Cython -i https://pypi.tuna.tsinghua.edu.cn/simple

Package            Version
------------------ ---------
appdirs            1.4.4
build              1.0.3
colorama           0.4.6
Cython             3.0.5
importlib-metadata 6.8.0
Jinja2             3.1.2
MarkupSafe         2.1.3
packaging          23.2
pip                20.0.2
pyproject-hooks    1.0.0
python-for-android 2023.9.16
setuptools         45.2.0
sh                 1.14.3
toml               0.10.2
tomli              2.0.1
wheel              0.34.2
zipp               3.17.0

I used python-for-andoid to build a flask program:

--bootstrap=webview  \
--requirements=python3==3.10.0,hostpython3==3.10.0,werkzeug==2.2.2,flask,typing_extensions,bleak,async_timeout

When my program calls the following code :

from jnius import autoclass
String = autoclass('java.lang.String')

adb show

11-22 12:14:36.257  8477 22911 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/jnius/reflect.py", line 209, in autoclass
11-22 12:14:36.257  8477 22911 I python  :   File "jnius/jnius_export_func.pxi", line 24, in jnius.jnius.find_javaclass
11-22 12:14:36.257  8477 22911 I python  :   File "jnius/jnius_export_class.pxi", line 266, in jnius.jnius.JavaClass.__init__
11-22 12:14:36.257  8477 22911 I python  : AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage'

help me

I used two mobile phones and a bluestack simulator, both of which reported the same error

@tsiens
Copy link
Author

tsiens commented Nov 22, 2023

I upgraded pyjnius to 1.6.1,but i use bleak

from bleak import BleakClient, BleakScanner
import asyncio
async def main():
    return [{'name': d.name, 'addr': d.address} for d in await BleakScanner.discover() if d.name]
print(asyncio.run(main()))

new error

11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/bleak/__init__.py", line 317, in discover
11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/bleak/__init__.py", line 145, in __init__
11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/bleak/backends/scanner.py", line 279, in get_platform_scanner_backend_type
11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/bleak/backends/p4android/scanner.py", line 20, in <module>
11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/bleak/backends/p4android/defs.py", line 32, in <module>
11-22 15:17:39.197 26650  3738 I python  :   File "/root/.local/share/python-for-android/build/python-installs/tda/arm64-v8a/jnius/reflect.py", line 209, in autoclass
11-22 15:17:39.197 26650  3738 I python  :   File "jnius/jnius_export_func.pxi", line 22, in jnius.jnius.find_javaclass
11-22 15:17:39.197 26650  3738 I python  :   File "jnius/jnius_utils.pxi", line 79, in jnius.jnius.check_exception
11-22 15:17:39.197 26650  3738 I python  : jnius.jnius.JavaException: JVM exception occurred: Didn't find class "com.github.hbldh.bleak.PythonScanCallback" on path: DexPathList[[zip file "/data/app/~~mxhtEbHpdi2pYmczUMA4Aw==/org.tsiens.tda-RJEZMqcdhMu-DpY0trVGsA==/base.apk"],nativeLibraryDirectories=[/data/app/~~mxhtEbHpdi2pYmczUMA4Aw==/org.tsiens.tda-RJEZMqcdhMu-DpY0trVGsA==/lib/arm64, /data/app/~~mxhtEbHpdi2pYmczUMA4Aw==/org.tsiens.tda-RJEZMqcdhMu-DpY0trVGsA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] java.lang.ClassNotFoundException
11-22 15:17:39.197 26650  3738 I python  : Python for android ended.

@Julian-O
Copy link
Contributor

python-for-android does not support Cython 3. kivy/python-for-android#2919

@Julian-O
Copy link
Contributor

Wait, you got a problem with an old version of PyJnius. You found an issue that said "Oh, use a newer one", so you used upgraded and the problem went away.

Yay.

Now, you are having a different problem with bleak, which provides its own p4a recipe.

This is a support problem - it doesn't belong here because we don't know (yet) if it is a problem with pyjnius at all.

Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants