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

"Class not found" when trying to access a class from .AAR imported with Gradle #544

Closed
st-den opened this issue Jun 3, 2020 · 3 comments

Comments

@st-den
Copy link

st-den commented Jun 3, 2020

A bit of history: trying to make TensorFlow Lite work on Android. The way they recommend isn't working for like 9 months now, and currently isn't a priority for them (issue). So the only thing left to try is adding an .AAR file and using the classes through pyjnius. Guide 1, guide 2, .AAR downloaded from here.

And when I do that, I get jnius.jnius.JavaException: Class not found b'org/tensorflow/lite'.

It is worth noting that I get libpythonXXX.so not found when I try to build with any version of TFLite .AAR for armeabi-v7a, which may be a separate issue and is probably harder to debug than this one. When I build other stuff, both arm64-v8a and armeabi-v7a builds work on my phone fine.

Tried 5 different versions of TFLite, two newest versions of Buildozer, p4a master/develop, cleaned everything multiple times, but no luck. Will be grateful for any tips.

Also, I may just be doing it all wrong, since I haven't found much info for such a case. So excuse my ignorance, if I missed something obvious.

@lerela
Copy link

lerela commented Jun 29, 2020

I'm seeing very similar behavior with AAR or with Java classes that are directly in my project, with pyjnius 1.3.0. Classes are present in the generated APK (as seen with an APK decompiler), yet the error I run into at runtime is the following:

Service: Traceback (most recent call last):
Service:   File "/home/user/hostcwd/.buildozer/android/app/lib/service.py", line 920, in _check_firmware_revision
Service:   File "/home/user/hostcwd/.buildozer/android/app/lib/service.py", line 847, in update_firmware
Service:   File "/home/user/hostcwd/.buildozer/android/platform/build-arm64-v8a/build/python-installs/app/jnius/reflect.py", line 229, in autoclass
Service:   File "jnius/jnius_export_func.pxi", line 26, in jnius.jnius.find_javaclass
Service:   File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception
Service: jnius.jnius.JavaException: JVM exception occurred: Didn't find class "org.company.package.FileTwo" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]] java.lang.ClassNotFoundException

After a lot of digging, it seems that the issue comes from imports that are not in the main thread. Moving all my imports to the top of my files, so that they are executed when the app is loaded, appears to have fixed it.

@rheasman
Copy link

@lerela, I just wanted to say that you probably saved me days of work. I am working on a project that is multiplatform, and some of the android code ended up in a different thread and hadn't been tested for months. It was a complete mystery why pyjnius was failing, now that we were testing android again, and almost all of the dependencies for this project had changed, so I had a huge pile of things to go through.

I wouldn't have figured this out any time soon.

Thank you

@github-actions
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
Projects
None yet
Development

No branches or pull requests

5 participants