kivy / pyjnius

Access Java classes from Python
https://pyjnius.readthedocs.org
MIT License
1.4k stars 255 forks source link

Strange errors when using via rpyc #235

Open Konubinix opened 8 years ago

Konubinix commented 8 years ago

My description just got lost in some stange github bug...

In brief, I can deploy an android application with buildozer and a main.py containing

String = autoclass("java.lang.String")
aaa = String("aaaaa")
acp = [0, 0, 0, 0]
aaa.getBytes(0,4,acp,0)
print(acp)

I will see the result [97, 97, 97, 97]

If I try to do the same via rpyc, I get the "No methods matching your arguments" error, like in the bug #58. '''python import rpyc_classic rpyc_classic.ClassicServer.run() ''' And from an ipython session, in my desktop, with the soo nice completion, syntax coloring etc.

import rpyc
conn = rpyc.classic.connect("deviceip")
autoclass = conn.modules.jnius.autoclass
const = autoclass('android.hardware.usb.UsbConstants')
const.USB_DIR_IN # this works, indicating that rpyc manages to correctly control the device from my computer
String = autoclass("java.lang.String")
aaa = String("aaaaa")
acp = [0, 0, 0, 0]
aaa.getBytes(0,4,acp,0)
print(acp) # this fails with the No method error

I would gladly suggest a PR, but don't know yet where to start searching to investigate the problem.

Except from that kind of bug, it is very nice to be able to play with my the android API of my phone with the comfort of an ipython session in my computer. Thank you for jnius :-).

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37533184-strange-errors-when-using-via-rpyc?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github).
inclement commented 8 years ago

I'm afraid I don't know what would cause this, probably you have to dig into the pyjnius code. It might be worth checking if there are any general limitations with rpyc, e.g. with cython code which pyjnius will be using (maybe there's nothing like this, I haven't tried it).

This is a very interesting idea though, I'd be very interested if you're able to get it working.

Konubinix commented 8 years ago

Thank you for answering.

Actually, I have thought of something. rpyc use an in-house proxying mechanism called netref to allow transparent use of objects. I think that when confronted with netref objects, pyjnius does not see the underlying object and try to convert a netref object into java instead of the underlying object.

I will try converting the rpyc object into a builtin copy (i.e. converting <netref (list)> into a ) and see if that fixes the problem.

I will try to feed this issue with the result of my quest.

If, in the main time, someone could tell me how to see the types pyjnius actually sees when trying to call a java method, that could help me a lot.

Konubinix commented 6 years ago

Thanks a lot to myself of the past. I totally forgot about the netref mechanism and spent a whole day trying to figure out why I could not communicate with my arduino board.

Indeed, performing the work in the android stack did the trick!