alnitak / flutter_soloud

Flutter low-level audio plugin using SoLoud C++ library and FFI
MIT License
223 stars 23 forks source link

fix: Not working when release for iOS #114

Closed Hoangkute123xyz closed 2 months ago

Hoangkute123xyz commented 3 months ago

I'm using this package for my iOS application and it's pretty cool for playing low latency audio. I built debug mode and ran release mode with "flutter run --release", everything works fine. But when I started distributing my app to the App store connect and used test flight to test my app, its broke. Sound cannot be played. I don't know how to debug my app after contributing to app store connection. Am I missing something in my implementation.

alnitak commented 3 months ago

Hi @Hoangkute123xyz,

I don't think this is a flutter_soloud bug. Maybe is something related to some other package you are using? Please, take a look at this issue.

Let me know!

Hoangkute123xyz commented 3 months ago

yeah, it's not working for me at first. So I thought it happened by audio session, but after I added audio_session, nothing changed. If I run my app via Xcode or the command "flutter run --release", everything works. Something is missing from my Xcode configuration? If you successfully release an iOS App using flutter_soloud, please let me know. U can simulate by build ipa then install it to your iOS device .Thank you so much.

alnitak commented 3 months ago

Sorry but I don't have a Mac to try out, but I am almost sure the guy writing in the issue I linked before successfully deployed to App Store.

If you have any news, please update this issue!

OshOEz commented 3 months ago

Hi @Hoangkute123xyz ! Your message made me feel not alone...

I've been struggling for the past few weeks with issue :

I have pushed a debug version of my app and the problem seems to come from the initialization part. I haven't found any solution yet and still trying to figure it out...

I hope that together we'll find a way to make this work

OshOEz commented 3 months ago

I really think this issue should be labelled as a bug.

Hi @Hoangkute123xyz,

I don't think this is a flutter_soloud bug. Maybe is something related to some other package you are using? Please, take a look at this issue.

Let me know!

I think this issue should really be labeled as a bug

OshOEz commented 3 months ago

Hi @Hoangkute123xyz,

I don't think this is a flutter_soloud bug. Maybe is something related to some other package you are using? Please, take a look at this issue.

Let me know!

The issue you mentioned is about problems flagged by Apple when pushing to the appstore. On my side (and surely @Hoangkute123xyz also), the deploying goes well. The problem is that the sounds dont play when released. (Looks like it's an initialization problem)

Regards

alnitak commented 3 months ago

Without a log to see where or when the problem occurs is very difficult for me to look for a solution or a suggestion. Also because I don't have a Mac anymore so please, I need help!

If there is no other way to see the logs on iOS when running an app installed from testflight, one thing we can try is to log into a Textfield and see what is causing the problem.

OshOEz commented 3 months ago

Without a log to see where or when the problem occurs is very difficult for me to look for a solution or a suggestion. Also because I don't have a Mac anymore so please, I need help!

If there is no other way to see the logs on iOS when running an app installed from testflight, one thing we can try is to log into a Textfield and see what is causing the problem.

Alright ! Thanks for your answer

I can add an on-device logging system. What logs do you need to debug this issue ?

alnitak commented 3 months ago

What logs do you need to debug this issue ?

Everything related to flutter_soloud from the start of the app. For example, if the init() method goes fine, as for the load*() and the play(). Just to see where the problem occurs.

Anyway are you sure is not possible to see logs from a running app installed from testflight? I remember it was somehow possible. I tried googling "ios see log of an app installed from testflight" and something came up. I would try to look at this before doing by hand a log system, also because the problem could be not related to the above flutter_soloud methods.

OshOEz commented 3 months ago

Hi ! So I added some debug labels in-app to see where it stops.

When plugged to VSCode, the initialization, assets loading and play3d function works well When on testflight, it fails during initialization : if (_soloud.isInitialized) { updateLogData("SOLOUD : Initialised"); } is never true. I can display some more data if you tell me which one you need.

Robin

alnitak commented 3 months ago

Well, that's not really a log :). You should print somewhere the exception that some methods throw. Something like:

try {
  _soloud.init();
} on Exception catch (e) {
  updateLogData("SOLOUD init() error: $e");
}

Thinking of what you wrote, the error could happen in _soloud_init() but I have no idea why this happens only when using an app installed from testflight.

Are you trying with the pub.dev version (2.0.2)?

Can you please try using the pitch branch? You can modify your pubspec.yam as following: instead of

  flutter_soloud: ^2.0.2

please try:

  flutter_soloud:
    git:
      url: https://github.com/alnitak/flutter_soloud
      ref: pitch

Hope we will find the problem!

OshOEz commented 3 months ago

Thanks for the answer ! Obviously it wasn't enough ^^ I'm trying the exception printing.

In the meanwhile, I tried to use the git source for soloud and a lot of errors were thrown while running. Putting them under : `Failed to build iOS app Could not build the precompiled application for the device. Lexical or Preprocessor Issue (Xcode): Too many arguments provided to function-like macro invocation /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.h:17:8

Semantic Issue (Xcode): 'virtual' can only appear on non-static member functions /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.h:14:4

Semantic Issue (Xcode): Field has incomplete type 'void' /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.h:14:17

Lexical or Preprocessor Issue (Xcode): Too few arguments provided to function-like macro invocation /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/filters.h:31:38

Parse Issue (Xcode): Expected '{' or ',' /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/filters.h:33:4

Semantic Issue (Xcode): No member named 'filesystem' in namespace 'std'; did you mean 'std::__fs::filesystem'? /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/bindings.cpp:223:8

Semantic Issue (Xcode): No member named 'filesystem' in namespace 'std'; did you mean 'std::__fs::filesystem'? /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/bindings.cpp:223:35

Semantic Issue (Xcode): Cannot initialize object parameter of type 'SoLoud::FilterInstance' with an expression of type 'PitchShiftInstance' /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:11:4

Lexical or Preprocessor Issue (Xcode): Too many arguments provided to function-like macro invocation /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:19:4

Semantic Issue (Xcode): Non-static data member defined out-of-line /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:16:25

Semantic Issue (Xcode): Use of undeclared identifier 'aTime' /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:24:17

Parse Issue (Xcode): Expected ';' after top level declarator /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:47:1

Semantic Issue (Xcode): Cannot initialize return object of type 'SoLoud::FilterInstance ' with an rvalue of type 'PitchShiftInstance ' /Users/robinlegal/Documents/Ezymob/App%20Ezymob/geospatial_plugin/example/ios/.symlinks/plugins/flutter_soloud/src/filters/pitch_shift_filter.cpp:168:11`

alnitak commented 3 months ago

@OshOEz I have built an OSX VM to fix it. It should now compile fine even if I cannot see the app content since Metal graphic is not supported in the VM and the OpenGL is no longer supported by Flutter on Mac.

To try I think you must do a flutter clean. Let me know!

OshOEz commented 3 months ago

@OshOEz I have built an OSX VM to fix it. It should now compile fine even if I cannot see the app content since Metal graphic is not supported in the VM and the OpenGL is no longer supported by Flutter on Mac.

To try I think you must do a flutter clean. Let me know!

Hi ! I tried the updated version of the git version provided and it runs well ! but the same thing happens. Have you tried putting an app with the plugin on testflight ?

Unfortunately, the sample provided doesn't give any info on the error thrown during the initialization...

alnitak commented 3 months ago

Have you tried putting an app with the plugin on testflight ?

I cannot try within a VM.

OshOEz commented 3 months ago

Okay, I modified the snippet to this : try { await _soloud.init(); } catch (e, stackTrace) { updateLogData("SOLOUD init() error: $e"); updateLogData("Stack trace: $stackTrace"); }

and finally got the initialization error details on the pitch git version :

SOLOUD : Starting initialization
SOLOUD init() error: 
Invalid argument(s): Failed to lookup symbol 'isInited': dlsym(RTLD_DEFAULT, isInited): symbol not found
flutter: Stack trace: #0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33)
#1      FlutterSoLoudFfi._isInitedPtr (package:flutter_soloud/src/bindings/bindings_player_ffi.dart:196)
#2      FlutterSoLoudFfi._isInited (package:flutter_soloud/src/bindings/bindings_player_ffi.dart)
#3      FlutterSoLoudFfi.isInited (package:flutter_soloud/src/bindings/bindings_player_ffi.dart)
#4      SoLoud.isInitialized (package:flutter_soloud/src/soloud.dart:176)
#5      SoLoud.init (package:flutter_soloud/src/soloud.dart:302)
#6      MapPageViewModel._initSoloud (package:geospatial_plugin_example/screen/map_page_viewmodel.dart:259)
#7      MapPageViewModel.init (package:geospatial_plugin_example/screen/map_page_viewmodel.dart:67)
#8      MapPage.build.<anonymous closure> (package:geospatial_plugin_example/screen/map_page_view.dart:21)
#9      ViewModelBuilderState._createViewModel (package:stacked/src/view_models/view_model_builder.dart:153)
#10     ViewModelBuilderState.initState (pa<…>

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to lookup symbol 'isInited': dlsym(RTLD_DEFAULT, isInited): symbol not found
#0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33)
#1      FlutterSoLoudFfi._isInitedPtr (package:flutter_soloud/src/bindings/bindings_player_ffi.dart:196)
#2      FlutterSoLoudFfi._isInited (package:flutter_soloud/src/bindings/bindings_player_ffi.dart)
#3      FlutterSoLoudFfi.isInited (package:flutter_soloud/src/bindings/bindings_player_ffi.dart)
#4      SoLoud.isInitialized (package:flutter_soloud/src/soloud.dart:176)
#5      MapPageViewModel._initSoloud (package:geospatial_plugin_example/screen/map_page_viewmodel.dart:265)
alnitak commented 3 months ago

Looks like that when building an ipa for testflight, XCode strips out native functions even if they are declared not to be striped. I didn't find a way to automatize this yet, but you can try to change the strip style in Target Runner:

Select Target Runner -> Build Settings -> Strip Style -> change from "All Symbols" to "Non-Global Symbols"

as described here which is a workaround for a still open Dart ffi issue.

Thanks for helping me. Let me know.

alnitak commented 3 months ago

This seems a common problem when building an ipa. tflite_flutter package has a similar problem:

When creating a release archive (IPA), the symbols are stripped by Xcode, so the command flutter build ipa may throw a Failed to lookup symbol ... symbol not found error. To work around this:

  1. In Xcode, go to Target Runner > Build Settings > Strip Style
  2. Change from All Symbols to Non-Global Symbols

@OshOEz, @Hoangkute123xyz if this works for you, I will update the README.md.

update it's also stated in the official Flutter docs.

OshOEz commented 2 months ago

@alnitak thank you for the hard work, it works fine now !

I'll try soon with the pub.dev version (2.0.2) but it should works fine. I'll keep you posted

alnitak commented 2 months ago

Version 2.1.0 is landed with the README.md updated.

Thanks a lot @OshOEz and @Hoangkute123xyz.