pyCharm - PyJnius - libjvm.so error (Linux Mint)

154 visualizzazioni
Passa al primo messaggio da leggere

Pete Kovac

da leggere,
13 nov 2022, 17:30:3913/11/22
a Kivy users support
Hi All,

Normally I wouldn't ask for help directly but this one is driving me nutso. I've been getting this error no matter what I try.

Unable to find libjvm.so, (tried ['/usr/lib/jvm/java-17-oracle/lib/server/libjvm.so', '/usr/lib/jvm/java-17-oracle/jre/lib/amd64/default/libjvm.so', '/usr/lib/jvm/java-17-oracle/jre/lib/amd64/server/libjvm.so'])

PyCharm works, opens up, even Android Studio opens up without an issue and is able to run java. 

Here's my java environment setup
export J2SDKDIR=/usr/lib/jvm/java-17-oracle
export J2REDIR=/usr/lib/jvm/java-17-oracle
export PATH=$PATH:/usr/lib/jvm/java-17-oracle/bin:/usr/lib/jvm/java-17-oracle/db/bin
export JAVA_HOME=/usr/lib/jvm/java-17-oracle
export DERBY_HOME=/usr/lib/jvm/java-17-oracle/db

I can see the file in the path so I'm lost at this point. I've tried purging java and reinstalling it, no dice. I've tried editing and putting in JAVA_HOME in etc/profile and no dice, as well as in ~/.bashrc no dice. 

Any help is appreciated from the group.

Robert

da leggere,
13 nov 2022, 20:25:0613/11/22
a Kivy users support
Mine is here - but mine is openJDK

~>find /usr -name libjvm.so
/usr/lib/jvm/java-17-openjdk-amd64/lib/server/libjvm.so

Robin Barrett

da leggere,
13 nov 2022, 21:12:4113/11/22
a kivy-...@googlegroups.com
I'm not sure what is throwing the error? When/where are you seeing it?

--
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/2382552b-a0f0-4f43-b02c-7ce2e4e92f43n%40googlegroups.com.

Pete Kovac

da leggere,
14 nov 2022, 08:46:2514/11/22
a Kivy users support
The error is on compiling and running the code and its just a simple example of wifi - here is the code

import kivy
from jnius import autoclass
from kivymd.app import MDApp
from kivy.lang.builder import Builder
import kivymd
from kivymd.uix.button import MDRoundFlatButton
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.toast import toast

String = autoclass('java.lang.String')

WifiConfigure = autoclass('android.net.wifi.WifiConfiguration')

PythonActivity = autoclass('org.kivy.android.PythonActivity')
activity = PythonActivity.mActivity

service = activity.getSystemService("wifi")

WifiManager = autoclass('android.net.wifi.WifiManager')
# The WifiManager methods are static which means that you do not have to instantiate the class
#export JAVA_HOME=/usr/lib/jvm/java-17-oracle/
WifiConfig = WifiConfigure()
# Instant the class since its methods are public and not static

Robert

da leggere,
14 nov 2022, 12:13:3514/11/22
a Kivy users support
What OS are you seeing the error on?

The android packages are only available on Android (https://github.com/Android-for-Python/Android-for-Python-Users#pyjnius )
But the error is seems to suggest looking for the jvm on Linux.

Pete Kovac

da leggere,
14 nov 2022, 12:29:3414/11/22
a Kivy users support
Hi Robert,

I am on a Linux box - perhaps I'm looking at this the wrong way - are we to include all of our code in python then build the APK to test out if the code works as desired on Android? Kind of fly blind, build APK, ADB APK, test, rinse and repeat...? New to Kivy and mobile - have my app 70% done, just need to figure out how to use wifi from the phone, doing this on a desktop application is easy, with mobile I find it to be very interestingly confusing. 

Robert

da leggere,
14 nov 2022, 20:04:5814/11/22
a Kivy users support
Attempt to address flying blind by first reading the docs, at least that should get you clear on your questions; if not the answers.
Please don't make us try to guess.


I think the first paragraph here https://github.com/Android-for-Python/Android-for-Python-Users#basic-pyjnius-usage addresses your question about debugging when you access the Android apis directly.


> just need to figure out how to use wifi from the phone
It depends what you want to do with wifi, if you just want internet protocols then there is noting to do except enable permission.
https://github.com/Android-for-Python/Android-for-Python-Users#meta-information
Also read about buildozer.spec https://buildozer.readthedocs.io/en/latest/specifications.html or https://github.com/Android-for-Python/Android-for-Python-Users#buildozer-and-p4a

I see that you are using WifiConfiguration, so perhaps you are doing something else. In which case you need the Android documentation for the api and the required permissions. 

Pete Kovac

da leggere,
15 nov 2022, 08:41:4515/11/22
a Kivy users support
Thanks Robert - that now makes sense. Build the Python/Kivy framework in PyCharm with all the python libraries as well as with Kivy screens, then once the framework is completed and tested on Android go back to PyCharm and start to add in the pyjinus Android classes and code, once that's done compile the APK with Buildozer and load onto the device to test functionality. Go back to PyCharm if any issues and repeat the process. 

All I'm trying to do is scan for wifi networks, pick one, enter password, if password is correct remember the SSID and Password to store it in a file that will be sent to a Raspberry Pi over Bluetooth to configure the Pi in a headless operation to what Wifi Network it can connect too.

Appreciate all the help!

Pete Kovac

da leggere,
15 nov 2022, 18:15:0815/11/22
a Kivy users support
Thanks Robert - all that information was a lot to digest and it helped out a TON. It helped me figure out how to set permissions in the app as well as in Buildozer. I have now a nice list of wifi networks after hitting the scan button. You ROCK! Still learning this stuff and with groups like this it makes it actually fun and enjoyable to do. 

Robert

da leggere,
15 nov 2022, 19:07:3215/11/22
a Kivy users support
😎Its nice to see things actually work after moving up a learning curve.

Pete Kovac

da leggere,
17 nov 2022, 11:38:4217/11/22
a Kivy users support

Sure is - I got everything working nicely in Python to get the newtwork ID and have the user enter in a password. I then call the connect to function of wifidroid and get an error
jnius.jnius.JavaException: Cannot call instance method b'addNetwork' on class b'android/net/wifi/WifiManager' - any idea where to start with this one?

Here is my code snipit:

def accept_password(self, password):
     global wifi_network_selected_name
     print(password)
     wifi_password=password
     print(wifi_network_selected_name)
     wifi = WifiManager()
     wifi.ConnectWifiWpa(wifi_network_selected_name, wifi_password)
     pass
Il messaggio è stato eliminato

Robert

da leggere,
17 nov 2022, 13:13:1617/11/22
a Kivy users support
Same answer, the docs, this time its Android docs - the method is depreciated.


Presumably this is related to the "wifidroid" you reference (but I have no idea what that is).

Pete Kovac

da leggere,
17 nov 2022, 13:22:4217/11/22
a Kivy users support
Thanks again Robert - getting into the weeds now of this Android documentation - last time the WifiDroid was updated was 2 years ago - so that may not have been the best choice to use in the first place. Wasn't thinking about depreciation of calls in it. Will keep digging to see if there's another more recent method that's already been created, if not i'll have to learn Java. Thinking perhaps it would have been better to just fire up Android Studio and learn that from scratch. But I just love Kivy so much :)

Here the link for WifiDroid

Robert

da leggere,
17 nov 2022, 13:45:2117/11/22
a Kivy users support
Android is a moving target, p4a handles this for pure Python apps but Jnius usage is outside that.
Whatever language you use the OS as a moving target will be an issue.

Ok so now you have to look at the new wifi Java apis.
It doesn't mean the whole app has to be Java, take a look at why wifidroid (used to) work.
Some words on pyjnius:
My guess would be the callbacks from Java to Python will be the hardest part.

I can't know if this or AS is easier for you, but you do have options.
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi