swiftlang / swiftlang/swift-java
JavaKitSampleApp can't build with .interoperabilityMode(.Cxx) in swiftSettings
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
Commit : up to date
Context : While to build Samples/JavaKitSampleApp with adding .interoperabilityMode(.Cxx) in swiftSettings, I noticed the error message like below
macro expansion @JavaImplementation:2:6: error: method cannot be marked '@_cdecl' because the type of the parameter 1 cannot be represented in Objective-C
- /Users/zhaoyu/repos/swift-java/Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift:105:2: note: expanded code originates here 20 | } 21 | 22 | @JavaImplementation("com.example.swift.HelloSwift") | - note: in expansion of macro 'JavaImplementation' on extension of class 'HelloSwift' here
23 | extension HelloSwift: HelloSwiftNativeMethods {
24 | @JavaMethod
:
103 | throw SwiftWrappedError.message(message)
104 | }
105 | }
+--- 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!))
+-------------------------------------------------------------------
106 |
Steps to reproduce:
- git clone https://github.com/swiftlang/swift-java.git
- cd swift-java/Samples/JavaKitSamleApp
- Add a line .interoperabilityMode(.Cxx) in the swiftSettings of the target JavaKitSample
- swift build
Environment:
% swift --version
Apple Swift version 6.2 (swift-6.2-RELEASE)
Target: arm64-apple-macosx15.0
Build config: +assertions
% java --version
openjdk 25 2025-09-16 LTS
OpenJDK Runtime Environment Temurin-25+36 (build 25+36-LTS)
OpenJDK 64-Bit Server VM Temurin-25+36 (build 25+36-LTS, mixed mode, sharing)
macOS 15.4.1 (24E263) on a Mac mini M2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift, especially the @JavaImplementation expansion around HelloSwift and sayHello. Add .interoperabilityMode(.Cxx) to the JavaKitSample target's swiftSettings, run swift build, and trace why the generated @_cdecl method rejects its parameter; done means the sample builds successfully with Cxx interoperability enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, java, swift
- Domain
- build-system, developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100