Closed zhpixel517 closed 4 months ago
I am not an expert of cpal, and from the errors you mentioned, it seems to be related to cpal instead of flutter-rust-bridge. My naive guess of "jniLibs folder missing" is to create an empty folder.
would this be something to take up with the cpal people instead?
I think so, maybe try to ask there since it looks like a general "how to compile cpal on android".
I was able to fix it. My original issue was that I couldn't actually find the libc++_shared.so
on my system. The docs say that you can find it in $ANDROID_NDK/toolchains/llvm/prebuilt/
which is true, but in my case I had to search even deeper to find them in $ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib
. Then inside that directory are the different folders for x86_64-linux-android
, aarch64-linux-android
, etc.
I had to make the jniLibs
folder inside android/app/src
, then inside that folder create folders with these names and copy the libc++_shared.so
from each one into the new folders separately.
Next I added this to my android/app/src/build.gradle
inside android { ....
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs = ['src/jniLibs']
}
}
Finally , based on this, my build.rs
looks like this:
#[allow(dead_code)]
fn add_lib(name: impl AsRef<str>, _static: bool)
{
#[cfg(not(feature = "test"))]
println!(
"cargo:rustc-link-lib={}{}",
if _static { "static=" } else { "" },
name.as_ref()
);
}
fn main()
{
let target = std::env::var("TARGET").expect("ERR: Could not check the target for the build.");
if target.contains("android") {
add_lib("c++_shared", false);
}
}
unfortunately, copying the build.rs
sample from the doc's troubleshooting page about this issue didn't work for me. in fact with this setup, it actually brought Could not resolve symbol __cxa_pure_virtual
error back.
after these steps, the issue is solved. For extra reference, here is a template repo someone setup with cpal
setup on Android.
Happy to see the cpal compilation problem is fixed!
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.
Describe the bug
I've been trying to use the
cpal
crate on Android, but I am getting this error:I know that this error is the same as this previous issue, but I have tried the suggestions in that issue here. That links to a 404 github page, but I was able to find the correct link for it here and add this code to my
build.rs
:this does not fix the error, but it changes it to this:
I searched through the documentation and I followed instructions on solving these kinds of errors here, by replacing the code in
build.rs
to this:I started to follow instructions:
however, I don't have any folder in my project called jniLibs, my
android
folder looks like this:furthermore, the contents of
ANDROID_NDK/toolchains/llvm/prebuilt
just have a folder calleddarwin-x86_64
which has a bunch of random stuff in it.ANDROID_NDK
is~/Library/Android/sdk/ndk/27.0.12.077973/
.I tried these solutions to no success:
https://github.com/RustAudio/cpal/issues/720#issuecomment-1311813294
https://discuss.gradle.org/t/jni-libs-missing-in-apk-need-some-help-here/9292
https://github.com/RustAudio/cpal/issues/563#issuecomment-1271637282 (couldn't do this one either, because my jniLibs folder is missing)
https://github.com/fzyzcjy/flutter_rust_bridge/issues/1058#issuecomment-1441925923
https://github.com/katyo/oboe-rs/issues/14
https://github.com/fzyzcjy/flutter_rust_bridge/issues/1058#issuecomment-1443469761
would this be something to take up with the
cpal
people instead?Steps to reproduce
Create a new project with
flutter_rust_bridge_codegen create
, addcpal
to cargo, and run this:Logs
Expected behavior
No response
Generated binding code
No response
OS
No response
Version of
flutter_rust_bridge_codegen
No response
Flutter info
No response
Version of
clang++
No response
Additional context
No response