title: Making Xcode embed necessary dylibs
body: <p>I'm trying to do something pretty simple and typical, which is use dynamically linked libraries in my Xcode project and then deploy with all the necessary libraries embedded.</p>
  
  <p>However I must be doing something the wrong way, because Xcode 8 won't allow me to embed .dylib files, only frameworks! The picture below is what happens when I try to add anything to Embedded Binaires, the dylibs just don't show up, and Add Other... adds them to the project but not to Embedded Binaries.</p>
  
  <p><a href="https://i.imgur.com/kWCD00l.png" rel="noreferrer"><img src="https://i.imgur.com/kWCD00l.png" alt="Xcode not allowing me to add any of the dylibs as embedded binaries"></a></p>
  
  <p>There must be a very simple way to do it but I just can't find it...</p>
  
  <p><strong>Epilogue</strong></p>
  
  <p>So apparently since I do need to run a script that calls <code>install_lib_tool</code> I made a pretty universal script that will change anything that has <code>/local/</code> in its path to the path of the embedded copy:</p>
  
  <pre><code>#!/bin/sh
  
  app=$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH
  fw_path=$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH
  app_dyl_list=(`ls $fw_path | grep dylib`)
  
  function change_paths {
      local bin=$1
      echo change_path $bin
      dyl_list=(`otool -L $bin | grep local | awk '{print $1}'`)
  
      for dyl in ${dyl_list[*]}; do
          libname=$(basename $dyl)
          libname=${libname%%.*}
          actual_libname=(`ls $fw_path | grep $libname | xargs basename`)
          install_name_tool -change $dyl "@executable_path/../Frameworks/$actual_libname" $bin
          printf "\t%s edited\n" $actual_libname
      done
  }
  
  change_paths $app
  for dyl_bin in ${app_dyl_list[*]}; do
      change_paths $fw_path/$dyl_bin
  done
  </code></pre>
  
  <p>Then all it takes is adding a Run Script step after the copying of the dylibs to just run it with no arguments (the environment variables contain everything needed).</p>