-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Android: Fix JavaClassWrapper
so it actually works
#96182
Conversation
b91ad68
to
469cacc
Compare
So it's true. I have been ASKING everyone. I have had people reach out to me, asking what these classes actually do because I used to be the only one brave enough to figure it out and you're telling me they did NOT work for who knows how long, potentially since their conception. |
469cacc
to
44712f1
Compare
From the look of the code, I get the impression that these classes were partially ported from somewhere else where they were originally working, but the port was never fully finished. And, yeah, looking at the That said, the changes to get them working weren't really all that big :-) |
ec49f18
to
abd9dbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have not been able to test this yet, but the code looks good to me!
abd9dbb
to
98b9309
Compare
@@ -395,10 +409,10 @@ Variant::Type get_jni_type(const String &p_type) { | |||
idx++; | |||
} | |||
|
|||
return Variant::NIL; | |||
return Variant::OBJECT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this assumes we have an object if we don't match any of the other types, correct?
Should it also checks if the type starts with L
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this assumes we have an object if we don't match any of the other types, correct?
Yes
Should it also checks if the type starts with L?
This particular function gets class names (for non-arrays) as plain strings without the L
prefix and ;
suffix. So, for example, I made a JNISingleton
in a Godot Android plugin that takes a java.time.format.DateTimeFormatter
as an argument, and this function gets exactly the string "java.time.format.DateTimeFormatter"
.
98b9309
to
78883a5
Compare
Thanks! |
Just as a note, it would be nice to document in prior versions that these classes literally do not work. |
What form should that take? It could be a "note" in the description of the classes, although, it seems like that could potentially be easy to miss amid the description of what the classes and functions should be doing. Or should we remove the existing descriptions and only have the note? Only Godot 4.3 has full documentation of those classes - in Godot 4.2 and below they are undocumented - so returning to a largely undocumented state for 4.3 could make sense? |
Well if they really don't work in 4.3, this is a bugfix and should likely be cherry-picked, instead of documenting that they're useless. |
They haven't worked since their conception. So "this" should be cherrypicked to 3.x as well, which I'm not sure is easier than noting it down. |
My first inclination would be to not cherry-pick this. Even though the classes existed, the fact that they didn't really work means this is basically totally new functionality. I feel like it'd be best to go through the usual dev -> beta -> rc process to get testing and shake out bugs. |
JavaClassWrapper
so it actually worksJavaClassWrapper
so it actually works
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
The Android plugin implementation is updated to use `JavaClassWrapper` which was fixed in godotengine#96182, thus removing the limitation on supported types. Note that `JavaClassWrapper` has also been updated in order to only provide access to public methods and constructor to GDScript.
Thanks for the fix of `JavaClassWrapper` in godotengine#96182 and the changes in the previous commit, this introduces an `AndroidRuntime` plugin which provides GDScript access to the Android runtime capabilities. This allows developers to get access to various Android capabilities without the need of a plugin. For example, the following logic can be used to check whether the device supports vibration: ``` var android_runtime = Engine.get_singleton("AndroidRuntime") if android_runtime: print("Checking if the device supports vibration") var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") if vibrator_service: if vibrator_service.hasVibrator(): print("Vibration is supported on device!") else: printerr("Vibration is not supported on device") else: printerr("Unable to retrieve the vibrator service") else: printerr("Couldn't find AndroidRuntime singleton") ```
Currently,
JavaClassWrapper
has most of the code in order to work, but is missing a bunch of the pieces to connect it all together, and, in fact, doesn't actually do anything. :-)This PR aims to get it minimally working, so that you can create Java objects and call their methods.
It also allows
JavaObject
s to be passed as arguments to methods onJNISingleton
s registered by Godot Android Plugins, and for any unknown objects that are returned from such methods to be turned intoJavaObject
s.Here's some example GDScript code:
There's still a bunch of things that don't work, namely accessing fields and constants. Also, this code could use some refactoring and clean-up. There's also some amount of code duplication between
JavaClassWrapper
andJNISingleton
.But this PR doesn't address those things - just getting it minimally working. Further work can be done in follow-up PRs.