espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of PDFium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
117 stars 55 forks source link

Invalid argument(s): Failed to load dynamic library 'pdfrx.framework/pdfrx' #212

Open pierlucatonioloreply opened 4 months ago

pierlucatonioloreply commented 4 months ago

Hi, when I try to use pdfrx to open a pdf on iOS (real device and simulator) I have a blue screen with this error:

Invalid argument(s): Failed to load dynamic library 'pdfrx.framework/pdfrx': dlopen(pdfrx.framework/pdfrx, 0x0001): tried: 'pdfrx.framework/pdfrx' (no such file), '/private/preboot/Cryptexes/OSpdfrx.framework/pdfrx' (no such file), '/usr/lib/swift/pdfrx.framework/pdfrx' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/pdfrx.framework/pdfrx' (no such file), '/private/var/containers/Bundle/Application/1E7BCA5E-33B9-4AC7-83A9-9723BDC25A5C/Runner.app/Frameworks/pdfrx.framework/pdfrx' (no such file), '/usr/lib/pdfrx.framework/pdfrx' (no such file, not in dyld cache), 'pdfrx.framework/pdfrx' (no such file), '/System/Library/Frameworks/pdfrx.framework/pdfrx' (no such file, not in dyld cache)

0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)

1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)

2 pdfium (package:pdfrx/src/pdfium/pdfrx_pdfium.dart:31:43)

3 pdfium (package:pdfrx/src/pdfium/pdfrx_pdfium.dart)

4 _init. (package:pdfrx/src/pdfium/pdfrx_pdfium.dart:46:7

.....

I have no problems with Android and I can see the pdf correctly.

Doctor summary (to see all details, run flutter doctor -v): [!] Flutter (Channel stable, 3.19.6, on macOS 14.5 23F79 darwin-arm64, locale en-IT) ! Warning: dart on your path resolves to /opt/homebrew/Cellar/dart/3.4.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/pierlucatoniolo/FlutterSdk/flutter. Consider adding /Users/pierlucatoniolo/FlutterSdk/flutter/bin to the front of your path. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] IntelliJ IDEA Community Edition (version 2023.1) [✓] VS Code (version 1.89.1) [✓] Connected device (4 available)
[✓] Network resources

! Doctor found issues in 1 category.

iOS 17.5.1

I have tried to clean and rebuild the project, from both xcode and flutter clean. I have tried to manually delete the build folder. I have tried to manually add the pdfrx.framework under "Framework, Libraries, and Embedded Content" in the general tab of the Runner target.

Thanks in advice for more suggestions

espresso3389 commented 4 months ago

Could you please also delete .pub_cache folder?

pierlucatonioloreply commented 4 months ago

Deleted the .pub_cache folder in my $HOME but I have the same error.

image

OCR-ed from your screenshot:

dynamic library 'pdfrx.framework/pdfrx': dlopen(pdfrx.framework/pdfrx, Ox0001): tried:

'/Library/Developer/CoreSimulator/Volumes/iOs_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRootpdfrx.framework/pdfrx' (no such file),
'/Library/Developer/CoreSimulator/Volumes/i0S_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/i0S 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/pdfrx.framework/pdfrx' (no such file),
'/usr/lib/swift/pdfrx.framework/pdfrx' (no such file, not in dyld cache),
'/Users/pierlucatoniolo/Library/Developer/CoreSimulator/Devices/D6817B61-ADO8-4F1E-9599-D9EB9A4 B5827/data/Containers/Bundle/Application/FA7AC6AD-F3BC-434C-A1DA-45128C16208D/Runner.app/Frameworks/pdfrx.framework/pdfrx' (no such file),
'/usr/lib/pdfrx.framework/pdfrx' (no such file, not in dyld cache),
'pdfrx.framework/pdfrx' (no such file),
espresso3389 commented 4 months ago

At least, the following folders are generated during the build:

I'm not sure what triggers your issue, please remove all of them and try again.

espresso3389 commented 4 months ago

Ah, could you please check the existence of the following file?

${workspaceRoot}/build/ios/Debug-iphoneos/Runner.app/Frameworks/pdfrx.framework/pdfrx

Debug-iphoneos may be different for each build config anyway.

tologonkudaiberdiuulu commented 4 months ago

same issue for me (

espresso3389 commented 4 months ago

@pierlucatonioloreply @tologonkudaiberdiuulu Could you please check the existence of the file above? Does it exist?

tologonkudaiberdiuulu commented 4 months ago

@espresso3389 I just made cleaned with flutter clean. And while installing pods.

image

Just hanged out like this. Not finishing installing

tologonkudaiberdiuulu commented 4 months ago

I got error @espresso3389

image
tologonkudaiberdiuulu commented 4 months ago

Finally it's installed. But when trying to build getting error again @espresso3389

image
tologonkudaiberdiuulu commented 4 months ago

Could you please check the existence of the file above? Does it exist?

I couldn't find

pierlucatonioloreply commented 4 months ago

@pierlucatonioloreply @tologonkudaiberdiuulu Could you please check the existence of the file above? Does it exist?

I have the file image

pierlucatonioloreply commented 4 months ago

@espresso3389 I just made cleaned with flutter clean. And while installing pods. image

Just hanged out like this. Not finishing installing

It took me a moment but it installed without errors. The blue screen with the error remains the same when I try to open the PDF

espresso3389 commented 4 months ago

@tologonkudaiberdiuulu

On your case, downloading of the pdfium-ios.tgz failed.

So, please fix your network environment to properly download the files.

Or, please manually download the files and place them on pdfium/.lib/pdfium-apple-v9 and retry the build.

pierlucatonioloreply commented 4 months ago

At least, the following folders are generated during the build:

  • ${workspaceRoot}/build
  • ${workspaceRoot}/ios/.symlinks
  • ${workspaceRoot}/ios/Pods
  • ~/.pub_cache

I'm not sure what triggers your issue, please remove all of them and try again.

I have tried it multiple times. Full clean of all autogenerated folders, cleaning the project from xcode -> product -> clean build folder, flutter clean, updating/reinstalling with pod install, deleting pubspec.lock and podfile.lock. I also tried to manually add the pdfrx.framework here in the "Build Phases" of the runner target in xcode (I don't remember which folder I took the reference to pdfrx from) image

espresso3389 commented 4 months ago

@pierlucatonioloreply I have completely no idea what's happenning on your env. What plugins do you use with your app?

pierlucatonioloreply commented 4 months ago

@pierlucatonioloreply I have completely no idea what's happenning on your env. What plugins do you use with your app?

this is the list. Last action that I have done is -> flutter pub upgrade --major-versions. I have done this to upgrade from pdf_renderer to the last version of pdfrx.

dependencies: flutter: sdk: flutter http: ^1.2.2 flutter_command: ^5.0.0+17 get_it_mixin: ^4.2.2 get_it: ^7.2.0 flutter_triple: ^1.2.4+3 json_annotation: ^4.1.0 flutter_secure_storage: ^9.2.2 visibility_detector: ^0.4.0+2

flutter_cached_pdfview: ^0.4.2

cupertino_icons: ^1.0.2 retrofit: any logger: ^2.4.0 flutter_dotenv: ^5.0.2 local_auth: ^2.1.6 intl: ^0.17.0 flutter_html: ^3.0.0-alpha.2 webview_flutter: ^3.0.0 url_launcher: ^6.0.18 file_picker: ^8.0.5 pdfrx: ^1.0.82 google_maps_flutter: ^2.1.1 charts_flutter_new: ^0.12.0 decimal: ^2.1.0 flutter_svg: ^2.0.10+1 flutter_screenutil: ^5.3.1 flutter_slidable: ^3.0.1 image_picker: ^1.1.2 share_plus: ^9.0.0 flutter_polyline_points: ^2.1.0 photo_view: ^0.15.0 uuid: ^4.4.2 device_info_plus: ^10.1.0 package_info_plus: ^8.0.0 secure_application: ^4.0.1 flutter_exif_rotation: ^0.5.0 html_unescape: ^2.0.0 pull_to_refresh: ^2.0.0 shared_preferences: ^2.0.13 time_machine: ^0.9.17 firebase_core: ^3.2.0 firebase_analytics: ^11.2.0 firebase_performance: ^0.10.0+3 firebase_crashlytics: ^4.0.3 dotted_border: ^2.0.0+3 dio: ^5.0.0 upgrader: ^10.3.0 dropdown_button2: ^2.1.3 cached_network_image: ^3.2.3 path_provider: ^2.1.0 geocoding: ^3.0.0 maps_launcher: ^2.2.0 geolocator: ^12.0.0 intl_phone_number_input: ^0.7.2 timezone: ^0.9.2 flutter_cache_manager: ^3.3.1 pinput: ^2.3.0 provider: ^6.1.1

espresso3389 commented 4 months ago

Wow, it's too many... My guess is that some of the other plugins interferes the build of pdfrx. Basic strategy is that:

  1. Create a new empty app
  2. Add pfdrx and add the basic code to load some PDF (possiblly asset is a better choise)
  3. Add the plugins one by one and run the app

So could you do that?

espresso3389 commented 4 months ago

On the screenshot, the critical issue here is:

'/Users/pierlucatoniolo/Library/Developer/CoreSimulator/Devices/D6817B61-ADO8-4F1E-9599-D9EB9A4B5827/data/Containers/Bundle/Application/FA7AC6AD-F3BC-434C-A1DA-45128C16208D/Runner.app/Frameworks/pdfrx.framework/pdfrx' (no such file)

It means your Runner.app does not contain pdfrx binary there. It means some build process removes the binary or framework. Something in your Podfile may remove the binary...

Did you modify your Podfile to do something special?

espresso3389 commented 4 months ago

Mmm, no... I "believe" that build/ios/Debug-iphonesimulator/Runner.app or such should be identical to the actual ipa file installed on the device. But pdfrx binary seems to exist there...

espresso3389 commented 4 months ago

https://github.com/espresso3389/pdfrx/issues/212#issuecomment-2238930639 says "no such file". Sometimes error is "could not be loaded" or such if dependencies are missing or anyway the file is broken. The file apparently does not exist. What's happening on archiving or installing...

espresso3389 commented 4 months ago

Oh, we also need to clear Pod cache (~/Library/Caches/CocoaPods). How is it?

pierlucatonioloreply commented 4 months ago

One comment to reply all:

I have tried starting again from my branch with pdf_render. 1) Upgrade all to --major-versions except 3 packages whose update introduces too many errors -> with pdf_render I can see the pdfs. 2) Added pdfrx and used file() instead of openFile() -> I see the error instead of the pdf.

maybe I should try with a new project to see if is another package that cause this issue, as you suggested before.

eugeneyjy commented 2 months ago

Try doing this inside your project root folder. I face the same problem and doing these commands fix the problem for me.

pod cache clean --all
rm -rf ~/Library/Caches/CocoaPods
rm -rf ios/Pods

Edit: Never mind, it was something wrong in my ios/Podfile. In my case, inside the Podfile, there is a chunk of code

target 'Runner' do
  use_frameworks! :linkage => :static
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

Once I removed :linkage => :static from the code and then remove ios/Pods before rebuild, I get pdf showing in my page without error. You might want to clean other cache like I stated above too before rebuilding, but essentially the line :linkage => :static caused me the problem.

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end