1) I cut-n-paste the javauuid example code provided in livecode.com/docs/9-5-0/extending-livecode/extending-livecode/
2) Using Tools > Extension Builder - this would not initially compile, but after a little research I added "use com.livecode.foreign" and "use com.livecode.java", and then it did compile & package. I'll put the final code below, but the only changes that I made are the 2 lines mentioned.
3) I managed to add javauuid to my Tools > Extension Manager > Library without any problems.
4) I then created a stack, added a button, and put this in the mouse up handler - Answer GetRandomUUIDJava()
When I click on the button in the Windows IDE - LC gives me an error message - execution error at line 4 (LCB Error in file C:/Users/Kim/Desktop/LCB_UUID/Test_UUID.lcb at line 30: Unable to bind foreign handler com.livecode.library.test_uuid.JNI_RandomUUID)
When I click on the button on my Android test device - the button just blinks but does nothing.
Should LCB + FFI + Java work on Windows? Ultimately i don't need a Windows deploy. I was only hoping to be able to test on Windows.
How should I be doing debugging LCB + FFI + Java? How can I narrow down what my Android deployment is unhappy about?
Plus - any advice on how to get around this binding error would be much appreciated.
Thanks in advance and stay safe
Kim (LC 9.5 Indy, Windows 10, Android 8.1)
* FYI - the two tasks that I'm hoping to build up to are:
- return the filepath to the Android system downloads folder (the one that gmail writes downloaded files to); and
- return a list of the IDs of bluetooth devices that are in range of the Android device
Code: Select all
library com.livecode.library.test_uuid
metadata title is "Java UUID"
metadata author is "LiveCode"
metadata version is "1.0.0"
use com.livecode.foreign
use com.livecode.java
// Bind to the static randomUUID() method of the java.util.UUID class
__safe foreign handler JNI_RandomUUID() returns JObject binds to "java:java.util.UUID>randomUUID()Ljava/util/UUID;!static"
// Bind to the toString() instance method of the java.util.UUID class
__safe foreign handler JNI_UUIDToString(in pUUID as JObject) returns JString binds to "java:java.util.UUID>toString()Ljava/lang/String;"
// Library public handler - this will be accessible from LiveCode
// when this library is loaded. The following comment block will
// be used to generate the documentation
/**
Returns a new random UUID.
Returns (String):
The string representation of a type 4 (pseudo randomly generated)
UUID.
*/
public handler GetRandomUUIDJava() returns String
// Call the static randomUUID method to return an instance of
// the UUID class
variable tUUID as JObject
put JNI_RandomUUID() into tUUID
// Call the toString method on the UUID instance to obtain the
// (java) string representation of the UUID
variable tUUIDString as JString
put JNI_UUIDToString(tUUID) into tUUIDString
// Convert to a LiveCode String and return
return StringFromJString(tUUIDString)
end handler
end library