The target

  1. Building an SDK
  2. Building an App
  3. App integration SDK
  4. Modify SDK, debug in App
  5. Output the SDK

steps

1. Create a local working folder

The working directory contains the SDK + App project

2. Create a workspace

Create a new empty workspace

3. Create a Framework

Create the FRAMEWORK for the SDK in the working directory

4. Create a Demo App

Create Demo in the working directory

5. Link Demo and SDK

  1. Open theworkspaceaddAdd Files to 'xxx.workspace'Find the SDK and Demoxcodeprojadded
  2. Select the SDK project and findBuild Settingssearchmach-o typeModified toStatic LibraryStatic library
  3. The selectedBuild PhasesAdd a scriptNew Run Script Phase, export the products after compiling SDK (including real machine and simulator), as follows
# Framework library merge script # go to the previous level of the project home directory,.. / indicates to go back to the level-1 directory. cd ${PROJECT_DIR}/.. / # create a '/Frameworks' folder, Mkdir -p output CD output # create a '/output' folder for the SDK mkdir -p output CD output # Use the lipo-create command to merge. cp -rf ${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/${PRODUCT_NAME}.framework ./ iphoneosFile=${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework/${PRODUCT_NAME} iphonesimulatorFile=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/${PRODUCT_NAME} if [ -f "$iphoneosFile" ] && [ -f "$iphonesimulatorFile" ]; then lipo -create "$iphoneosFile" "$iphonesimulatorFile" -output ./${PRODUCT_NAME}.framework/${PRODUCT_NAME} fi rm -rf ./${PRODUCT_NAME}.framework/_CodeSignatureCopy the code
  1. Xcode compilation target select SDK, build generationframework
  2. Add SDK under Demo project:Add Files to 'Demo'To find/Framework/outputPath, select the exported SDK product
  3. Remove the simulator library when Demo is packaged (optional) and select Demo to add scriptsNew Run Script Phase
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}" if [[ $APP_PATH != *ArchiveIntermediates* ]]; then exit 0 fi # This script loops through the frameworks embedded in the application and # removes unused architectures. find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK do FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable) FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME" echo "Executable is $FRAMEWORK_EXECUTABLE_PATH" EXTRACTED_ARCHS=() for ARCH in $ARCHS do echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME" lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH" EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")  done echo "Merging extracted architectures: ${ARCHS}" lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}" rm "${EXTRACTED_ARCHS[@]}" echo "Replacing original executable with thinned version" rm "$FRAMEWORK_EXECUTABLE_PATH" mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH" doneCopy the code

6. Debugging

  1. After the SDK is built, it is open to the public by defaultxxx.h(SDK name), we can import directly in Demo#import <SDK/SDK.h>
  2. The SDK provides additional to the host if needed.h: Select SDK project and findBuild Phases -> Headers -> PublicPull all the classes that need to be exposedpublicIn the can
  3. Xcode will first check the status of the dependent libraries when compiling the Demo. If the SDK changes, it will recompile the SDK output, and then compile the Demo after linking