-
-
Save madhavajay/39ff8bfee92e7cd97ea4270b8c99b3bc to your computer and use it in GitHub Desktop.
| # VERSION 1.0.4 | |
| # Author: @madhavajay | |
| # This currently works for iOS and watchOS in the Simulator and Devices | |
| # Changes | |
| # Using ${TOOLCHAIN} in two places now | |
| # Added double quotes " around paths | |
| # Fixed watchOS Issues | |
| # Instructions iOS | |
| # 1. Copy this into a new Build Phase Script for your App Target | |
| # 2. Add all the Frameworks you need as Input Files, internal and external | |
| # 3. Reset your iOS and watchOS simulators (seriously) | |
| # Screenshot: http://i.imgur.com/3dTjVcW.png | |
| # Instructions watchOS | |
| # 1. Same as above only you need to add the Build Phase Script and its | |
| # Framework Input Files to both the Watch App and the Watch Extension. | |
| # You can only add the Extension one in Xcode. So Add the Extension one, | |
| # then open the .xcodeproj in a Text Editor and find the Entry you just added. | |
| # Its a lot easier with Git. There will be two, changes, one like this: | |
| # | |
| # 28F65CA91D3FDC7D00043613 /* Fix Xcode 8 Beta 3 */ | |
| # | |
| # Under the WatchKit Extension buildPhases, and a second with the actual | |
| # script and inputs. | |
| # 2. Cut and Paste the Line like above, linking the Script from the Extension | |
| # Build Phase to the WatchKit App buildPhases. | |
| # 3. Make a new one for the WatchKit Extension Again, either in Xcode or | |
| # Text Editor. | |
| # 4. Reset your iOS and watchOS simulators (seriously) | |
| # 5. Clean deriveddata, spin around in your chair, build and shazam! | |
| # Whats happening here is the same Copy Swift standard libraries step is performed | |
| # on both the App and the Extension Targets. I was able to get the app running | |
| # with only one of these but i'm skeptical its correct as you can see Xcode | |
| # attempts the Copy Swift standard libraries on both Targets by default so there | |
| # must be a need for it. | |
| # Note, you should use the Beta 3 Toolchain, so make sure $TOOLCHAIN_DIR is resolving to: | |
| # /Applications/{YOUR BETA}.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain | |
| # Trouble Shooting | |
| # Check the Build Logs and you should see the New Step you add for each target. | |
| # If its working you can see the files like libswiftCore.dylib appear in the | |
| # Framework folders of your .app and .appex files. | |
| # If its not working, try putting `set` on a new line of your Build Phase Script | |
| # This will echo out all the Environment Variables used below and you can compare them | |
| # with the expected output that Xcode uses in the normal Build Step. | |
| # Be careful the Path Spaces are escaped by using double " around the paths below | |
| # or the build paths for watchOS wont work, because they have spaces in their | |
| # folder names like: APPNAME WatchKit Extension and APPNAME WatchKit App | |
| # Include Frameworks | |
| for i in `seq 1 ${SCRIPT_INPUT_FILE_COUNT}`; do | |
| NUM=`expr $i - 1` | |
| NEXT_FOLDER_ARG=SCRIPT_INPUT_FILE_$NUM | |
| INCLUDE_FRAMEWORK_FOLDER_ARGS="${INCLUDE_FRAMEWORK_FOLDER_ARGS} --scan-folder ${!NEXT_FOLDER_ARG}" | |
| done | |
| # Run the correct tool 🤗 | |
| ${TOOLCHAIN_DIR}/usr/bin/swift-stdlib-tool \ | |
| --copy --verbose --sign ${EXPANDED_CODE_SIGN_IDENTITY} \ | |
| --scan-executable "${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}" \ | |
| --scan-folder "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" \ | |
| --scan-folder "${TARGET_BUILD_DIR}/${PLUGINS_FOLDER_PATH}" \ | |
| --platform ${PLATFORM_NAME} \ | |
| --toolchain ${TOOLCHAIN_DIR} \ | |
| --destination "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" \ | |
| --strip-bitcode --resource-destination "${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}" \ | |
| --resource-library libswiftRemoteMirror.dylib \ | |
| ${INCLUDE_FRAMEWORK_FOLDER_ARGS} |
Woohoo! Glad it helped and even gladder its fixed in Xcode. Thanks to everyone who helped with this.
@madhavajay do we still need this for Xcode 8.1 and above?
Xcode 9.3, and I'm still using this script to solve swift problems on objc projects.
🥇
I'm using Cocoapods. Can I use this script to sole my problem too? In my case, if I build a fat framework it doesn't build my app. It gives me a invalid bitcode signature when linking with my swift pods. If I build just for active architecture, it gives me a runtime error dyld: Library not loaded: @rpath/...reason; Image not found when loading the app. I looked inside the app container and all swift libraries and all my pods frameworks are there inside Frameworks and my @Runpath does have Frameworks dir in it.
Xcode's
builtin-swiftStdLibToolbug appears to be fixed as of Xcode 8 beta 6.