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

java.lang.UnsatisfiedLinkError: dlopen failed: library "librust.so" not found #127

Closed
opfromthestart opened this issue Jun 2, 2023 · 7 comments

Comments

@opfromthestart
Copy link

I am trying to do a simple example at https://github.com/opfromthestart/openfunny.
No matter what I do, I always get this error when running the application. The .so files appear in both the rust/target and app/build/rustJniLibs directories, but it always gives this error. I am new to android development and have had no success for multiple hours.

@opfromthestart
Copy link
Author

I found a workaround by running ./gradlew installDebug but I would prefer a solution that works with closer to default Android Studio.

@SergioRibera
Copy link

@opfromthestart You have to specify the targetDirectory as this is because the rustJniLibs folder is empty, this is better explained here, but in summary add this

cargo {
  // ...
  targetDirectory = "../path/to/target/"
}

Note: If you have problems with the libc++_shared library, add this to your build.gradle

@kirillzh
Copy link

kirillzh commented Jun 27, 2023

For what it's worth, we started seeing the same issue with Android Gradle Plugin 7.4.2+. AGP 7.4.0 worked fine without additional configuration.

@opfromthestart
Copy link
Author

The files are being copied fine
image
but it still gives the error that it cannot find librust.so

@kirillzh
Copy link

This workaround seemed to work for me #118 (comment)

@opfromthestart
Copy link
Author

That still does not work. I updated the repo to reflect my changes

@opfromthestart
Copy link
Author

opfromthestart commented Jun 28, 2023

I fixed it by changing "cdylib" to "staticlib" and "dylib"
It looks like I actually fixed it by temporarily adding , "build/rustJniLibs/android/x86" to sourceSets.main.jniLibs.srcDirs. And yes, this did still work when building for arm64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants