简体   繁体   中英

Creating iOS Framework for device and Universal configuration with bitcode enable and bitcode disable from Command Line terminal

#!/bin/sh

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO \
    -configuration  ${CONFIGURATION} -sdk iphoneos  \
    BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} \
    -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" \
    BUILD_ROOT="${BUILD_ROOT}" clean build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"


# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" \
    "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" \ 
    "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"

I have above shell script to create framework for device and universal from Xcode build options.

Is is possible to create/Generate iOS Framework from Command terminal with above shell script with below configuration???

  • 1) Create framework for device bitcode disable
  • 2) Create framework for device bitcode enable
  • 3) Create framework for Universal bitcode disable
  • 4) Create framework for Universal bitcode enable

Please let me know the steps to create/generate iOS Framework from command terminal. Must appreciate for the best explanation

Just add the argument to your xcodebuild

ENABLE_BITCODE=NO for disabling bitcode

ENABLE_BITCODE=YES for enabling bitcode

For example

xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=NO

In the shell script you posted, replace the code under # Step 1. Build Device and Simulator versions with the following appropriately.

1) Create framework for device bitcode disable:

xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO \
-configuration  ${CONFIGURATION} -sdk iphoneos  \
BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=NO
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} \
-sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=YES

2) Create framework for device bitcode enable

xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO \
-configuration  ${CONFIGURATION} -sdk iphoneos  \
BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=YES
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} \
-sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=YES

3) Create framework for Universal bitcode disable

xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO \
-configuration  ${CONFIGURATION} -sdk iphoneos  \
BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=NO
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} \
-sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=NO

4) Create framework for Universal bitcode enable

 xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO \
-configuration  ${CONFIGURATION} -sdk iphoneos  \
BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=YES
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} \
-sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" clean build ENABLE_BITCODE=YES

EDIT:
To build the framework, you can do either of the below:
1. Replacing the code for each config, go to terminal and run the shell script by navigating to the folder containing the shell script and running ./<nameOfTheShellScriptFile>.sh . But make sure you have the build settings available there. That will create the framework with the appropriate configuration in the directory ${BUILD_DIR}/${CONFIGURATION}-universal .
2. Add a run script in the Xcode. Open your project in Xcode, click on the schemes dropdown (beside Stop button) and choose your framework scheme. Open the dropdown again and click on "Edit Scheme...". You see 6 actions to the left. You choose which action makes more sense to add the script to (do you want to create this universal framework on every Run action or only when you archive?). Drop down that action and click on Post-actions. Click on + button to add a new action and click on "New Run Script Action". Set the "Provide build settings from" to your framework target to get the appropriate build settings. Paste the script in the text area and click close. Now after every time you perform the action you put the script under, the script runs and builds the framework again for both device and simulator architectures and puts the universal framework in your project directory. It takes some time for this to complete especially if your project is big so wait patiently until the finder opens up to reveal your project directory containing the framework. Now you can either change the code in the script every time you want a different config (bitcode enabled or disabled), or add different schemes for different config and follow this whole step for each of the schemes with appropriate script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM