Undefined symbol: _JNI_CreateJavaVM & _JNI_GetCreatedJavaVMs during building Xcode project
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 38/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Domaine
- build-system, developer-experience
Piste de recherche
Commencez par les linkerSettings signalés de Package.swift et les produits SwiftJava et CSwiftJavaJNI, puis comparez le swift build réussi avec la compilation Xcode macOS qui échoue sur arm64. Reproduisez les erreurs de symboles non définis _JNI_CreateJavaVM et _JNI_GetCreatedJavaVMs à l’aide des détails fournis concernant Java et la toolchain. La tâche est terminée lorsque le projet Xcode lie les symboles JNI tout en conservant les types Swift Java générés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Commit hash: d087f65caa3dfb1f0582568ce6e2ee0cf69ed717
Context:
I have built simple Swift package, that contains jar file and uses SwiftJava to get artifacts of Java types that were declared in that .jar file, to use them inside the library. I have provided swift-java.config file for desired types.
I used swift build command for the package. Which resulted in successful building and corresponding Swift's representation of Java types were generated in .build directory of my package. So, from my understanding I have set everything up correctly, otherwise those files wouldn't even be generated.
But, once I added this local package to Xcode macOS project I keep getting error from SwiftJava package, which prevents my project from building:
Undefined symbol: _JNI_CreateJavaVM
Undefined symbol: _JNI_GetCreatedJavaVMs
Undefined symbols for architecture arm64:
"_JNI_CreateJavaVM", referenced from:
SwiftJava.JavaVirtualMachine.(in _6C47C84FF2986D473D4896464216BF8F).init(classpath: [Swift.String], vmOptions: [Swift.String], ignoreUnrecognized: Swift.Bool) throws -> SwiftJava.JavaVirtualMachine in SwiftJava.o
"_JNI_GetCreatedJavaVMs", referenced from:
closure #2 @Sendable (inout SwiftJava.JavaVirtualMachine?) throws -> SwiftJava.JavaVirtualMachine in static SwiftJava.JavaVirtualMachine.shared(classpath: [Swift.String], vmOptions: [Swift.String], ignoreUnrecognized: Swift.Bool, replace: Swift.Bool) throws -> SwiftJava.JavaVirtualMachine in SwiftJava.o
ld: symbol(s) not found for architecture arm64
I have tried to specify path for linker in my Package.swift file, in order to find correct libjvm.dylib file, but that doesn't seem to be related to this, since SwiftJava is complaining.
Package.swift content of my package I'm adding to my project
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import CompilerPluginSupport
import PackageDescription
import class Foundation.FileManager
import class Foundation.ProcessInfo
func findJavaHome() -> String {
if let home: String = ProcessInfo.processInfo.environment["JAVA_HOME"] {
return home
}
let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home"
if let home: String = try? String(contentsOfFile: path, encoding: .utf8) {
if let lastChar = home.last, lastChar.isNewline {
return String(home.dropLast())
}
return home
}
fatalError("Please set the JAVA_HOME environment variable to point where Java is installed: \(path)")
}
let java_home = findJavaHome()
let javaIncludePath = "\(java_home)/include"
let javaPlatformIncludePath = "\(javaIncludePath)/darwin"
let homebrewJavaPath = "/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
let package = Package(
name: "MyPackage",
platforms: [.macOS(.v15)],
products: [.library(name: "MyPackage", type: .dynamic, targets: ["MyPackage"])],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-java", branch: "main")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "MyPackage",
dependencies: [
.product(name: "SwiftJava", package: "swift-java"),
.product(name: "CSwiftJavaJNI", package: "swift-java"),
.product(name: "SwiftJavaConfigurationShared", package: "swift-java"),
.product(name: "SwiftRuntimeFunctions", package: "swift-java")
],
exclude: ["swift-java.config"],
swiftSettings: [
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
.swiftLanguageMode(.v5)
],
linkerSettings: [
.unsafeFlags([
"-L\(homebrewJavaPath)/lib/server",
"-ljvm"
])
],
plugins: [
.plugin(name: "JExtractSwiftPlugin", package: "swift-java"),
.plugin(name: "SwiftJavaPlugin", package: "swift-java")
]
),
]
)
Probably some relevant info about system:
MacBook Air M1
Operating system: MacOS 26.2
swift-driver version: 1.127.14.1 Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)
Target: arm64-apple-macosx26.0
/usr/libexec/java_home -V:
Matching Java Virtual Machines (1):
25.0.2 (arm64) "Homebrew" - "OpenJDK 25.0.2" /opt/homebrew/Cellar/openjdk/25.0.2/libexec/openjdk.jdk/Contents/Home
java -version:
openjdk version "25.0.2" 2026-01-20
OpenJDK Runtime Environment Homebrew (build 25.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 25.0.2, mixed mode, sharing)
- Langage dominant
- Swift
- Étoiles
- 1.3k
- Forks
- 127
- Merge moyen
- 1 h 6 min
- PR mergées (30 j)
- 3
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de swiftlang/swift-java
-
Document main actor execution requirements in Java-hosted processesPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
swiftlang/swift-java#955 ·
Les mainteneurs répondent en général sous 1 jour
-
wrap-java: Optional convenience methods can fail to compile when a parameter shadows the method nameOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
swiftlang/swift-java#945 ·
Les mainteneurs répondent en général sous 1 jour
-
android
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
swiftlang/swift-java#663 · 4 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 56/100
swiftlang/swift-java#949 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
swiftlang/swift-java#948 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de swiftlang/swift-java
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
vorssaint/vorssaint-utils#3917 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
swiftlang/swift-markdown#299 ·
-
send.tracked never delivers to SMS or RCS chats: lowercased GUIDs stay unsent with error 4Peut-être pris @thurstonsand l’a pris aujourd’hui. Ouverteclawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P1
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
openclaw/imsg#390 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
area: agents follow-up
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
manaflow-ai/cmux#37234 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
thunderbird/thunderbird-ios#628 ·
Les mainteneurs répondent en général sous 1 jour