title: dyld: Library not loaded with XCFramework for device but works with Simulator
body: <p>I built a universal XCFramework by following this guide <a href="https://medium.com/@anuragajwani/how-to-build-universal-ios-static-libraries-using-xcframework-a3f70f998c38" rel="nofollow noreferrer">https://medium.com/@anuragajwani/how-to-build-universal-ios-static-libraries-using-xcframework-a3f70f998c38</a>, using the following commands:</p>
  <pre><code>xcodebuild build \
    -scheme myApp \
    -derivedDataPath derived_data \
    -arch arm64 \
    -sdk iphoneos \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES
  mkdir -p build/devices
  cp -r derived_data/Build/Products/Debug-iphoneos/ build/devices
  
  xcodebuild build \
    -scheme myApp \
    -derivedDataPath derived_data \
    -arch x86_64 \
    -sdk iphonesimulator \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES
  mkdir -p build/simulators
  cp -r derived_data/Build/Products/Debug-iphonesimulator/ build/simulators
  
  xcodebuild -create-xcframework \
      -framework build/simulators/myApp.framework \
      -framework build/devices/myApp.framework \
      -output build/myApp.xcframework
  </code></pre>
  <p>This built a <code>myApp.xcframework</code>, which contains both <code>ios-arm64</code> and <code>ios-x86_64-simulator</code> directories.</p>
  <p>I'd like to distribute this to a few customers and both devices and Simulators should be supported.</p>
  <p>I imported <code>myApp.xcframework</code> into a different project, and in General made sure that the framework is listed and &quot;Embed &amp; Sign&quot; is set.</p>
  <p>I can run the project and make use of the framework just fine with the simulator. However, when I try to run it on the device I get the following:</p>
  <pre><code>dyld: Library not loaded: @rpath/myApp.framework/myApp
    Referenced from: /private/var/containers/Bundle/Application/16EC2405-9C65-4DED-BFF6-4A2546397BC9/myApp.app/myApp
    Reason: image not found
  </code></pre>
  <p>If I, however, only use the <code>myApp.framework</code> from the <code>ios-arm64</code> directory of the XCFramework and import this, the application works on the device. It seems the problem is not with the built framework itself, but with it not being able to locate the correct framework for a device.</p>
  <p>Any help would be greatly appreciated!</p>