objectbox / objectbox/objectbox-java

UnsatisfiedLinkError: no objectbox-jni-windows-x64 when installed to Program Files

未关闭
#1,225 9 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

documentation enhancement
主要语言
Java
星标
4.6k
派生
311
PR 合并指标
30 天内没有已合并 PR

描述

Is there an existing issue?
Build info
  • ObjectBox version: 5.0.0
  • OS: Windows 10
  • Device/ABI/architecture: x64
Steps to reproduce

I am building a KMP project with ObjectBox. When I run the jvmApp module directly (e.g., from the IDE), the ObjectBox .dll file is found and loaded correctly.

However, when I build a distributable package for deployment (e.g., using jpackage), the .dll file seems to be missing from the final package, causing it to fail at runtime.

What could be the problem?

(I apologize for asking this again. I posted this on StackOverflow, but since I haven't received a response yet, I'm posting it here as well.)

Expected behavior

Create objectbox-jni-windows-x64, when the installer installs the executable.

Actual behavior

The .dll file is not included when the installer installs the executable.

Code
Code

settings.gradle.kts(root)

pluginManagement {
    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "io.objectbox") {
                useModule("io.objectbox:objectbox-gradle-plugin:${requested.version}")
            }
            if (requested.id.id == "com.google.dagger") {
                useModule("com.google.dagger:dagger:${requested.version}")
            }
            if (requested.id.id == "com.google.dagger:hilt-android") {
                useModule("com.google.dagger:hilt-android:${requested.version}")
            }
        }
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "FireAlarmKMP"
include(":androidApp")
include(":jvmApp")
include(":shared:data-common")
include(":shared:data-jvm")
include(":shared:domain")
include(":shared:presentation-common")
include(":shared:data-android")
include(":shared:core-common")
include(":shared:core-android")
include(":shared:core-jvm")
include(":shared:presentation-android")
include(":shared:presentation-jvm")

build.gradle.kts(:jvmApp)

import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    alias(libs.plugins.jetbrains.kotlin.jvm)
    alias(libs.plugins.kotlin.compose)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.kapt)
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
    compilerOptions {
        jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
    }
}

dependencies {
    implementation(compose.desktop.currentOs)
    implementation(libs.kotlinx.coroutines.swing)
    implementation(libs.dagger)
    implementation(libs.androidx.lifecycle.viewmodel.compose)
    implementation(libs.androidx.lifecycle.runtime.compose)
    configurations["kapt"].dependencies.add(project.dependencies.create(libs.dagger.compiler.get()))
    implementation(project(":shared:presentation-common"))
    implementation(project(":shared:presentation-jvm"))
    implementation(project(":shared:domain"))
    implementation(project(":shared:data-common"))
    implementation(project(":shared:data-jvm"))
    implementation(project(":shared:core-common"))
    implementation(project(":shared:core-jvm"))
}

compose.desktop {
    application {
        mainClass = "com.blabla.jvmapp.MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb, TargetFormat.Exe)
            packageName = "jvmapp"
            packageVersion = "1.0.28"
        }
    }
}

build.gradle.kts(:data-jvm)

plugins {
    alias(libs.plugins.jetbrains.kotlin.jvm)
    alias(libs.plugins.kapt)
}
java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}
kotlin {
    compilerOptions {
        jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
    }
}

dependencies {
    implementation(libs.arrow.core)
    implementation(libs.arrow.fx.coroutines)
    implementation(libs.kotlinx.coroutines.core)
    implementation(libs.objectbox.windows)
    implementation(libs.objectbox.kotlin)
    kapt(libs.objectbox.processor)
    implementation(libs.dagger)
    kapt(libs.dagger.compiler)
    implementation(project(":shared:data-common"))
    implementation(project(":shared:core-common"))
    implementation(project(":shared:domain"))
}

apply(plugin = "java-library")
apply(plugin = "io.objectbox")
Logs, stack traces
Logs
Caused by: java.lang.UnsatisfiedLinkError: no objectbox-jni-windows-x64 in java.library.path: C:\Program Files\com.blabla.jvmapp\app/resources
	at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
	at java.base/java.lang.Runtime.loadLibrary0(Unknown Source)
	at java.base/java.lang.System.loadLibrary(Unknown Source)
	at io.objectbox.internal.NativeLibraryLoader.<clinit>(NativeLibraryLoader.java:98)
	... 48 more

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先从 :jvmApp 和 :data-jvm 中的 build.gradle.kts 开始,然后检查 Compose Desktop 的 nativeDistributions 配置以及已安装应用的资源目录。重新执行 Windows 软件包构建,并将其与直接运行的 JVM 应用进行比较,首先参考 UnsatisfiedLinkError 和 NativeLibraryLoader 的位置。完成的标准是打包的安装程序包含 objectbox-jni-windows-x64,并且已安装的应用能够在没有本机库错误的情况下启动。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, kotlin
领域
build-system, databases, desktop-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。