Cocoapod RealmSwift runtime error: `dyld: Library not loaded: @rpath/Realm.framework/Realm`

482 views Asked by At

I have a project that used to work fine on the device but it started failing after I have re-installed cocoapods. The weird thing is I don't get the problem while running in the simulator. I was also able to replicate the same problem with a completely new project. The exact error was:

dyld: Library not loaded: @rpath/Realm.framework/Realm
  Referenced from: /var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/myapp
  Reason: no suitable image found.  Did find:
    /private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm: code signing blocked mmap() of '/private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm'
    /private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm: code signing blocked mmap() of '/private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm'
    /private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm: code signing blocked mmap() of '/private/var/containers/Bundle/Application/34C8D121-9724-4C73-9B62-6F8932E5BFD7/myapp.app/Frameworks/Realm.framework/Realm'

What I have tried:

  • deleting derived data, cleaning Xcode project, restart xcode
  • removing the app on device, re-plugging the usb
  • cleared cocoapod cache
  • updated to latest RealmSwift

For anyone who wants to try, here's a sample project: https://github.com/schystz/TestRealmSwift

2

There are 2 answers

0
schystz On BEST ANSWER

Apparently, the cause of the issue is a development certificate that was automatically created by Xcode. The issue was fixed after I created the certificate manually (that is by uploading my csr, downloading and adding to keychain). I'm not sure why Xcode is like this cause automatic signing used to work before...

0
Edward Gray On

I had the same issue in Xcode 11.4 and I fixed it by editing my pod file to:

platform :ios, '13.0'

target 'YourTarget' do
  #use_frameworks! -> !!! very important

  pod 'Realm', :modular_headers => true
  pod 'RealmSwift', :modular_headers => true

end