Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distribute and use .so files for linux platform #3240

Closed
Lefix2 opened this issue Jun 6, 2023 · 8 comments
Closed

distribute and use .so files for linux platform #3240

Lefix2 opened this issue Jun 6, 2023 · 8 comments
Assignees
Labels
question Not a bug, but question or comment

Comments

@Lefix2
Copy link

Lefix2 commented Jun 6, 2023

Hello,

I'm struggling while installing/loading some dynamic libraries into my app.

I'm currently developing only for Linux but i want to be "future-proof" for possible windows port of my application.

Currently, i have so custom .so files, some used with jni, that i want to embed in my App without creating an AppImage.

The solution I found is to put my libraries into ${PROJECT_DIR}/main/resources/linux/lib/*.so and addig the following lines to my build.gradle:

compose.desktop {
    application {
        mainClass = "ManufacturingHostKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageVersion = "1.0.0"

            appResourcesRootDir.set(project.layout.projectDirectory.dir("resources"))
        }
    }
}

Then in my application load libraries with:


val resourcesDir = File(System.getProperty("compose.application.resources.dir"))
System.load(resourcesDir.resolve("lib/libMylib.so").path)

Note that calling a .so is platform dependant and I will prefer something like

System.loadLibrary("Mylib")

But when I create distributable (./gradlew createDistributable) the files are not copied into build/compose/binaries/main/app/MyApp/lib/app/resources/
At runtime, the path to search for library is correct:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: <path-to-my-app>/build/compose/binaries/main/app/MyApp/lib/app/resources/lib/libMylib.so
  • Kotlin version: jvm v1.8.20
  • Compose Multiplatform version: 1.4
@Lefix2 Lefix2 added bug Something isn't working submitted labels Jun 6, 2023
@m-sasha
Copy link
Member

m-sasha commented Jun 6, 2023

Does it work when you run the app from the IDE? Only the packaged app fails?

@Lefix2
Copy link
Author

Lefix2 commented Jun 6, 2023

Yes i tried everything, it fails as for 'run' and 'runDistributable'

I don't mentioned it but manually copying files works

@m-sasha
Copy link
Member

m-sasha commented Jun 6, 2023

@AlexeyTsvetkov Can you help here?

By the way, in my app I put resources (although they're not native libs) under src/main/resources/resource.ext and they are packaged and loadable with ClassLoader.getResourceAsStream without configuring anything in gradle at all.

@m-sasha m-sasha added question Not a bug, but question or comment and removed bug Something isn't working submitted labels Jun 6, 2023
@m-sasha
Copy link
Member

m-sasha commented Jun 6, 2023

@Lefix2 Also, you could ask in our #compose-desktop slack channel; maybe someone could help you faster.

@Lefix2
Copy link
Author

Lefix2 commented Jun 6, 2023

I've also pointed that:
For my app icon (in src/main/resources/icon.svg), it is loaded when i run the app but it is also not present in the distributable resource folder

@Lefix2
Copy link
Author

Lefix2 commented Jun 6, 2023

@Lefix2 Also, you could ask in our #compose-desktop slack channel; maybe someone could help you faster.

I'll do that!

@DatL4g
Copy link

DatL4g commented Jun 19, 2023

Take a look at this thread #2618

My native loader looks like this:

val resDir = File(systemProperty("compose.application.resources.dir"))
val libFile = File(resDir, libFilename(libName))

System.load(libFile.canonicalPath)

@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@JetBrains JetBrains locked and limited conversation to collaborators Dec 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Not a bug, but question or comment
Projects
None yet
Development

No branches or pull requests

5 participants