iOS app with framework crashed on device, dyld: Library not loaded, Xcode 6 Beta

后端 未结 30 2469
鱼传尺愫
鱼传尺愫 2020-11-22 10:08

This crash has been a blocking issue I used the following steps to reproduce the issue:

  • Create a Cocoa Touch Framework project
  • Add a swift file and a
相关标签:
30条回答
  • 2020-11-22 10:35

    I had the same issue. I tried building my project with an iPhone that I never used before and I didn't add a new framework. For me, cleaning up worked fine (Shift+Command+K). Maybe it's because I use beta 5 of Xcode 7 and an iPhone 6 with iOS 9 Beta, but it worked.

    0 讨论(0)
  • 2020-11-22 10:36

    If have development pod Delete your app from simulator install from pod -> clean - > run again...

    0 讨论(0)
  • 2020-11-22 10:37

    Just dragging the framework into your project isn't going to be good enough. That is like being in the same ballpark but not being able to find your kids. Follow these steps:

    1) Create your framework

    • Develop your framework.
    • Once your development is complete, COMMAND+B build your framework and ensure you receive "Build Succeeded".

    2) Access your framework

    • Once your framework project successfully builds it will then be ready for you to access in your Products folder in your project.

    • Right click on your .framework and select "Show in Finder".

    3) Place framework in your project

    • Drag and drop the .framework from your Finder window to your app project's "Framework" folder.

    4) Configure app project for framework

    • Select the top level in your project

    • Choose your target

    • Go to "Build Phases", then "Link Binary with Libraries", and ensure that your framework is included with optional selected.

    • Still in "Build Phases", go to the upper left and select the + button. In the drop down choose "New Copy Files Phase".

    • Scroll down to the new "Copy Files" section and ensure that you set Destination to "Frameworks". Leave the subpath empty. Then click the + button at the bottom left.

    • You will be presented with your project hierarchy. Scroll down to the "Frameworks" folder that you added the framework to in step 3, or search for it in the search bar at the top. Select your framework and click "Add".

    • Ensure that your framework is included with "Code Sign On Copy" selected.

    5) Clean, then run your project

    • COMMAND+SHIFT+K
    • COMMAND+R
    0 讨论(0)
  • 2020-11-22 10:37

    Add the framework in Embedded Binaries

    Then Clean and Build.

    0 讨论(0)
  • 2020-11-22 10:39

    You need to add the framework to a new Copy Files Build Phase to ensure that the framework is copied into the application bundle at runtime..

    See How to add a 'Copy Files build phase' to my Target for more information.

    Official Apple Docs: https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/CreatingaCopyFilesBuildPhase.html

    0 讨论(0)
  • 2020-11-22 10:39

    It is a runtime error that is caused by Dynamic Linker

    dyld: Library not loaded: @rpath/...
    ...
    Reason: image not found
    

    The error Library not loaded with @rpath indicates that Dynamic Linker cannot find the binary.

    1. Check if the dynamic framework was added to General -> Embedded Binaries

    2. Check the @rpath setup between consumer(application) and producer(dynamic framework):

      • Dynamic framework:
        • Build Settings -> Dynamic Library Install Name
      • Application:
        • Build Settings -> Runpath Search Paths
        • Build Phases -> Embed Frameworks -> Destination, Subpath

    Dynamic linker

    Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME) which is used by loadable bundle(Dynamic framework as a derivative) where dyld come into play
    Dynamic Library Install Name - path to binary file(not .framework). Yes, they have the same name, but MyFramework.framework is a packaged bundle with MyFramework binary file and resources inside.
    This path to directory can be absolute or relative(e.g. @executable_path, @loader_path, @rpath). Relative path is more preferable because it is changed together with an anchor that is useful when you distribute your bundle as a single directory

    absolute path - Framework1 example

    //Framework1 Dynamic Library Install Name
    /some_path/Framework1.framework/subfolder1
    

    @executable_path

    @executable_path - relative to entry binary - Framework2 example
    use case: embed a Dynamic framework into an application

    //Application bundle(`.app` package) absolute path
    /some_path/Application.аpp
    
    //Application binary absolute path 
    /some_path/Application.аpp/subfolder1
    
    //Framework2 binary absolute path
    /some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
    
    //Framework2 @executable_path == Application binary absolute path
    /some_path/Application.аpp/subfolder1
    
    //Framework2 Dynamic Library Install Name 
    @executable_path/../Frameworks/Framework2.framework/subfolder1
    
    //Framework2 binary resolved absolute path by dyld
    /some_path/Application.аpp/subfolder1/../Frameworks/Framework2.framework/subfolder1
    /some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
    

    @loader_path

    @loader_path - relative to bundle which is an owner of this binary
    use case: framework with embedded framework - Framework3_1 with Framework3_2 inside

    //Framework3_1 binary absolute path
    /some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1
    
    //Framework3_2 binary absolute path
    /some_path/Application.аpp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
    
    //Framework3_1 @executable_path == Application binary absolute path
    /some_path/Application.аpp/subfolder1
    
    //Framework3_1 @loader_path == Framework3_1 @executable_path
    /some_path/Application.аpp/subfolder1
    
    //Framework3_2 @executable_path == Application binary absolute path
    /some_path/Application.аpp/subfolder1
    
    //Framework3_2 @loader_path == Framework3_1 binary absolute path
    /some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1
    
    //Framework3_2 Dynamic Library Install Name 
    @loader_path/../Frameworks/Framework3_2.framework/subfolder1
    
    //Framework3_2 binary resolved absolute path by dyld
    /some_path/Application.аpp/Frameworks/Framework3_1.framework/subfolder1/../Frameworks/Framework3_2.framework/subfolder1
    /some_path/Application.аpp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
    

    @rpath - Runpath Search Path

    Framework2 example

    Previously we had to setup a Framework to work with dyld. It is not convenient because the same Framework can not be used with a different configurations

    @rpath is a compound concept that relies on outer(Application) and nested(Dynamic framework) parts:

    • Application:

      • Runpath Search Paths(LD_RUNPATH_SEARCH_PATHS) - defines a list of templates which be substituted with @rpath.
         @executable_path/../Frameworks
        
      • Review Build Phases -> Embed Frameworks -> Destination, Subpath to be shire where exactly the embed framework is located
    • Dynamic Framework:

      • Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME) - point that @rpath is used together with local bundle path to a binary
        @rpath/Framework2.framework/subfolder1
        
    //Application Runpath Search Paths
    @executable_path/../Frameworks
    
    //Framework2 Dynamic Library Install Name
    @rpath/Framework2.framework/subfolder1
    
    //Framework2 binary resolved absolute path by dyld
    //Framework2 @rpath is replaced by each element of Application Runpath Search Paths
    @executable_path/../Frameworks/Framework2.framework/subfolder1
    /some_path/Application.аpp/Frameworks/Framework2.framework/subfolder1
    

    *../ - go to the parent of the current directory

    otool - object file displaying tool

    //-L print shared libraries used
    //Application otool -L
    @rpath/Framework2.framework/subfolder1/Framework2
    
    //Framework2 otool -L
    @rpath/Framework2.framework/subfolder1/Framework2
    
    //-l print the load commands
    //Application otool -l
    LC_LOAD_DYLIB
    @rpath/Framework2.framework/subfolder1/Framework2
    
    LC_RPATH
    @executable_path/../Frameworks
    
    //Framework2 otool -l
    LC_ID_DYLIB
    @rpath/Framework2.framework/subfolder1/Framework2
    

    install_name_tool change dynamic shared library install names using -rpath

    CocoaPods uses use_frameworks![About] to regulate a Dynamic Linker

    [Vocabulary]

    0 讨论(0)
提交回复
热议问题