Thanks swift-java project, it makes a new way to share code between Java and Swift.
java -cp .build/plugins/outputs/javakitsampleapp/JavaKitExample/destination/JavaCompilerPlugin/Java "-Djava.library.path=.build/debug" com.example.swift.JavaKitSampleMain
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by com.example.swift.HelloSwift in an unnamed module (file:/D:/repos/test/swift-java/Samples/JavaKitSampleApp/.build/plugins/outputs/javakitsampleapp/JavaKitExample/destination/JavaCompilerPlugin/Java/)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
Hello from Swift!
And hello back from Java! You passed me 42
Swift got back 3.14159 from Java
We expect the above value to be the initial value, 3.14159
Updating Java field value to something different
And hello back from Java! You passed me 17
Swift got back updated 2.71828 from Java
Swift created a new Java instance with the value 3.14159
Hello to Java
Salutations, Swift ?? How's it going
And hello back from a ??-collected language! You passed me 42
Running a JavaPredicate from swift 3 < 10 = true
Converting doubles to strings: ["3.14159", "2.71828"]
Hello from the subclass!
Salutations, Swift
Salutations, Hello from Swift
Caught Java error: java.lang.Exception: I am an error
Optional text = Optional(SwiftJava.JavaString)
Optional string value = Optional("")
Optional text function returned Optional(SwiftJava.JavaString)
Optional double function returned Optional(2.0)
Optional long function returned Optional(21)
sayHello(17, 25) = 425
I found major problem when building is about Windows file path (the drive name, the separtor ; etc). I noticed there are some Windows compiler conditions in SwiftJavaTool already.
I wonder if there a plan to support Windows release?
Feel free to report issues and send in pull requests but currently we are not focused on Windows support, but overall it would be good to support in the future.
Thank you for kind welcome. I definitely will provide PR once comfortable with my changes.
Besides, one problem I have is a dependency Swift package has interoperabilityMode(.Cxx), so that cause all targets set interoperabilityMode(.Cxx) too. That will cause error:
macro expansion @JavaImplementation:2:6: error: method cannot be marked '@_cdecl' because the type of the parameter 1 cannot be represented in Objective-C - D:\repos\test\swift-java\Samples\JavaKitSampleApp\Sources\JavaKitExample\JavaKitExample.swift:125:2: note: expanded code originates here 22 | } 23 | 24 | @JavaImplementation("com.example.swift.HelloSwift") | - note: in expansion of macro 'JavaImplementation' on extension of class 'HelloSwift' here
25 | extension HelloSwift: HelloSwiftNativeMethods {
26 | @JavaMethod
:
123 | throw SwiftWrappedError.message(message)
124 | }
125 | }
+--- macro expansion @JavaImplementation ---------------------------
| 1 | @cdecl("Java_com_example_swift_HelloSwift_sayHello")
| 2 | func $s14JavaKitExample1_0A14ImplementationfMp_8sayHellofMu(environment: UnsafeMutablePointer<JNIEnv?>!, thisObj: jobject, _ i: Int32.JNIType, _ j: Int32.JNIType) -> Int32.JNIType {
| | `- error: method cannot be marked '@cdecl' because the type of the parameter 1 cannot be represented in Objective-C
| 3 | let obj = HelloSwift(javaThis: thisObj, environment: environment!)
| 4 | return obj.sayHello(: Int32(fromJNI: i, in: environment!), _: Int32(fromJNI: j, in: environment!))
+-------------------------------------------------------------------
With limited knowledge, Iβm not sure if this problem can be solved or workaround ?
Found a new interesting problem. The JavaKitSampleApp build/run no problem on Windows only Debug mode. On Release mode, the native methods not exported in result DLL.
I feel it possibly related to the non-public symbols strip in release build, but failed to fix it even make the protocol NativeMethods as public.