fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.1k stars 278 forks source link

iOS does not find input audio devices #1769

Closed tGrothmannFluffy closed 6 months ago

tGrothmannFluffy commented 6 months ago

Describe the bug

Hi there,

I am having this issue with cpal on iOS and I'm not sure where the problem is.

Steps to reproduce

using cpal run on iOS (simulator/device, debug/release)

let hosts = cpal::available_hosts();
log_string(format!("Available hosts: {:?}", hosts));

let host = cpal::default_host();
log_string(format!("default host: {:?}", host.id()));

log_string(format!(
    "Host num input devices: {:?}",
    host.input_devices().unwrap().count()
));

log_string(format!(
    "Host num output devices: {:?}",
    host.output_devices().unwrap().count()
));

Logs

will result in

Available hosts: [CoreAudio]
default host: CoreAudio
Host num input devices: 0
Host num output devices: 1

The microphone is discoverable using dart, though.


### Expected behavior

_No response_

### Generated binding code

_No response_

### OS

iOS

### Version of `flutter_rust_bridge_codegen`

1.82.5

### Flutter info

```shell
Flutter 3.19.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision bae5e49bc2 (7 days ago) • 2024-02-13 17:46:18 -0800
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1

Version of clang++

15

Additional context

No response

fzyzcjy commented 6 months ago

Hi, without more information, it seems that this is unrelated to flutter_rust_bridge, but something related to cpal, since flutter_rust_bridge does nothing special about audio. But if cpal finds no problem, feel free to ping here!

tGrothmannFluffy commented 6 months ago

To investigate this issue I started a clean project with flutter_rust_bridge create. There seems to have been quite a lot of changes so maybe that'll fix it, and I wanted to isolate the problem.

Here's the project: https://github.com/tGrothmannFluffy/flutter_rust_test_ios_mic

Unfortunately, I cannot get it to run, because of flutter not finding the rust library. This reminds me of https://github.com/fzyzcjy/flutter_rust_bridge/issues/1058

fzyzcjy commented 6 months ago

Unfortunately, I cannot get it to run, because of flutter not finding the rust library.

It would be great to show the errors, then I can have a look at it :)

tGrothmannFluffy commented 6 months ago

At first I got:

ld: Undefined symbols:
  _AudioComponentFindNext, referenced from:
      coreaudio::audio_unit::AudioUnit::new_with_flags::hf4630a21d4507d5a in librust_lib_ios_mic.a[x86_64][193](cpal-d9d78020be790fe8.cpal.3c4241f9eb44d5fe-cgu.1.rcgu.o)
  _AudioComponentInstanceDispose, referenced from:
      _$LT$coreaudio..audio_unit..AudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hca9ac08a097ea638 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioComponentInstanceNew, referenced from:
      coreaudio::audio_unit::AudioUnit::new_with_flags::hf4630a21d4507d5a in librust_lib_ios_mic.a[x86_64][193](cpal-d9d78020be790fe8.cpal.3c4241f9eb44d5fe-cgu.1.rcgu.o)
  _AudioOutputUnitStart, referenced from:
      coreaudio::audio_unit::AudioUnit::start::ha3f6f577c1e2c9e2 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioOutputUnitStop, referenced from:
      coreaudio::audio_unit::AudioUnit::stop::h1ffe47b7eca246c4 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioUnitGetProperty, referenced from:
      coreaudio::audio_unit::get_property::h2798000ba6c9efac in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
      coreaudio::audio_unit::get_property::hb3df5bf4d6c13bc6 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioUnitInitialize, referenced from:
      coreaudio::audio_unit::AudioUnit::new_with_flags::hf4630a21d4507d5a in librust_lib_ios_mic.a[x86_64][193](cpal-d9d78020be790fe8.cpal.3c4241f9eb44d5fe-cgu.1.rcgu.o)
      coreaudio::audio_unit::AudioUnit::initialize::h5dfce5fca15af1cb in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioUnitSetProperty, referenced from:
      coreaudio::audio_unit::set_property::heb86782b96e8de98 in librust_lib_ios_mic.a[x86_64][193](cpal-d9d78020be790fe8.cpal.3c4241f9eb44d5fe-cgu.1.rcgu.o)
      coreaudio::audio_unit::set_property::h06cbfefb4adac733 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
      coreaudio::audio_unit::set_property::h5d287565dc79a5e7 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
  _AudioUnitUninitialize, referenced from:
      coreaudio::audio_unit::AudioUnit::uninitialize::h6d92c7b18989dec5 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
      _$LT$coreaudio..audio_unit..AudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hca9ac08a097ea638 in librust_lib_ios_mic.a[x86_64][207](coreaudio-6f99948436ab866b.coreaudio.a083936386d5d26e-cgu.0.rcgu.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After that the build succeeds, but I get this runtime error:

ArgumentError (Invalid argument(s): Failed to load dynamic library 'rust_lib_ios_mic.framework/rust_lib_ios_mic':
dlopen(rust_lib_ios_mic.framework/rust_lib_ios_mic, 0x0001):
tried: '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRootrust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file),
'/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file),
'/usr/lib/swift/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file, no dyld cache),
'/Users/fluffy/Library/Developer/CoreSimulator/Devices/A75E74E2-9876-48FB-9388-477EA4C0B6E4/data/Containers/Bundle/Application/157F1C2C-CB4E-42C9-88DB-FD309E41AA44/Runner.app/Frameworks/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file),
'/Users/fluffy/Library/Developer/CoreSimulator/Devices/A75E74E2-9876-48FB-9388-477EA4C0B6E4/data/Containers/Bundle/Application/157F1C2C-CB4E-42C9-88DB-FD309E41AA44/Runner.app/Frameworks/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file),
'/usr/lib/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file, no dyld cache), 'rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file),
'/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/rust_lib_ios_mic.framework/rust_lib_ios_mic' (no such file))
fzyzcjy commented 6 months ago

Hmm, looks like maybe something related to Cargokit. Maybe debug by, e.g.: Check the generated app - does it have that framewok? does that framework have that library file?

tGrothmannFluffy commented 6 months ago

The issue seems to be closed by adding some code into AppDelegate. This is necessary since iOS 17. https://github.com/RustAudio/cpal/issues/842#issuecomment-1966408740

github-actions[bot] commented 5 months ago

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.