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
JavaClassWrapper.wrap() doesn't seem to work #22136
Comments
Can anyone still reproduce this bug in Godot 3.2.1 or any later release (e.g. 3.2.2-rc2)? |
我写了一个补丁来实现这一功能,允许使用JavaClassWrapper.wrap调用任意的java类,以及和android/modules互相调用,java类可以使用 class.new的方式生成实例 比如: var singleton = null
var rixnet = null;
func test_java_singleton():
var c_java = JavaClassWrapper.wrap("com/godot/game/testJava");
print("c_java==", c_java)
var c_test = c_java.initialize();
print("c_test=", c_test);
print("c_test kk^=", c_test.myFunction("in GD"))
func test_singleton():
rixnet = Engine.get_singleton("RixNet")
print("rixnet=", rixnet);
rixnet.connect("test.net", 5000, 1);
var test_packet = rixnet.getPacket();
print("test_packet= ", test_packet)
print("test_packet cmd=", test_packet.getCmd());
print("test_packet buf", test_packet.getBuf());
singleton = Engine.get_singleton("MySingleton")
print(singleton.myFunction("Hello"))
singleton.getInstanceId(get_instance_id())
func test_java():
test_singleton()
var java_c = JavaClassWrapper.wrap("com/godot/game/testJava2")
var java_packet = JavaClassWrapper.wrap("com/rix/lib/socket/Packet")
print("java_c = ", java_c)
var new_java = java_c.new()
print("new_java=", new_java)
print("new_java myFunction=", new_java.myFunction("GDTEST"))
print("new_java testString=", new_java.testString())
print("new_java testStringWithArgs=", new_java.testStringWithArgs("fff", 123))
var p = java_packet.new(10, 2, PoolByteArray([0xF,0xE,0xD,0xC,0xB,0xA,9,8,7,6,5,4,3,2,1,0]), 2)
print("packet=",p)
print("new_java testPacket", new_java.testPacket(3, p))
print("new_java testPacket 2", new_java.testPacket(2, p))
print("packet2=",p)
print("rix_net send=", rixnet.sendmessage(p))
func _ready():
test_java() java_source: patch: |
Class function called also should be ok Class.new function also should be ok All of function in plugins also should be visited.
Class function called also should be ok Class.new function also should be ok All of function in plugins also should be visited.
It's been years and I am still unsure on whether or not JavaClass and JavaClassWrapper do anything useful as exposed classes. Examples and actual use-cases are lacking. |
Basically JavaClassWrapper.wrap() has never worked. But it is tempting for people trying to get access to Android Classes. I did manage to the the java classes from the function by returning the correct value a modification I made to Godot code. But even then, it seems that the class deletes too many references which makes the Java Class holo which is still useless.
I think it could work great as the kivy project has something similiar in pyjinus.
I would like to get this to work, but I need help because I do not know C++ much at all.
Godot version:
ALL
OS/device including version:
Android
Issue description:
JavaClassWrapper.wrap() returns [Object:null]
After patch it returns [JavaClass] but it seems to be holo, no class methods or class variables.
Some proof that JavaClassWrapper.wrap() is actually getting a class from the JNI.
The text was updated successfully, but these errors were encountered: