在Xcode 10上为通用框架运行脚本

时间:2019-01-30 07:40:46

标签: ios xcode xcode10 ios-frameworks ios-universal-framework

我使用Xcode 9.x,我使用的是以下脚本,该脚本运行良好:

######################
# Options
######################

REVEAL_ARCHIVE_IN_FINDER=false

FRAMEWORK_NAME="${PROJECT_NAME}"

SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"

DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"

UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"

FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"


######################
# Build Frameworks
######################

xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphonesimulator
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="i386 x86_64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1

xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphoneos
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="armv7 armv7s arm64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1

######################
# Create directory for universal
######################

rm -rf "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${FRAMEWORK}"


######################
# Copy files Framework
######################

cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"


######################
# Make an universal binary
######################

lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo

# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
                                                                      fi

                                                                      if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
                                                                      cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
                                                                      fi

                                                                      ######################
                                                                      # On Release, copy the result to release directory
                                                                      ######################
                                                                      OUTPUT_DIR="${PROJECT_DIR}/Output/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"

                                                                      rm -rf "$OUTPUT_DIR"
                                                                      mkdir -p "$OUTPUT_DIR"

                                                                      cp -r "${FRAMEWORK}" "$OUTPUT_DIR"

                                                                      if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
                                                                      open "${OUTPUT_DIR}/"
                                                                      fi

这不适用于 Xcode 10 。后来我看到脚本中需要进行一些修改。因此,我按照this的答案来设置脚本。但是设置此脚本后,当我尝试构建通用框架时,Xcode会挂在构建脚本1(共1)上。
我一直在寻找正确的解决方案,但每次都失败。
什么是Xcode 10上通用框架(覆盖所有体系结构)的正确运行脚本?

3 个答案:

答案 0 :(得分:4)

向xcodebuild命令添加#Tue Oct 16 17:39:45 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 应该可以。

-UseModernBuildSystem=NO

它应该可以解决您的问题。

这是我当前正在使用的整个脚本,并且可以使用Xcode 10成功构建通用框架。Link to gist

当前,正在努力利用最新的构建系统来构建通用框架。尽快更新答案。

答案 1 :(得分:0)

echo "project"
#open "${PROJECT_DIR}"
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"

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

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

# Step 1. Build Device and Simulator versions
echo "iphone"
xcodebuild -target "${TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
echo "iphonesim"
xcodebuild -target "${TARGET_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
echo "universal"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
echo "iphone simulator path"
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "lipo create"
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}"

echo "end"
fi

首先为模拟器和设备生成单独的版本 在打开“产品”文件夹时,您将找到两个单独的版本 然后在您的项目中使用此运行脚本

生成脚本后,您在同一产品文件夹中找到IOS通用文件夹

对我来说很好。

image

下面的屏幕截图

答案 2 :(得分:0)

打开终端,导航到项目的根目录用你的项目名称和方案名称(如果需要)替换你的UniversalFramework,运行命令成功后,它会生成通用文件夹内部构建

来自通用文件夹的框架现在可以被设备和模拟器使用了!

注意:在更改并运行后将整个脚本粘贴到终端上

enter image description here

.xcodeproj 项目的命令/脚本

mkdir build
    ;
    xcodebuild clean build \
      -project YourUniversalFramework.xcodeproj \
      -scheme YourUniversalFramework \
      -configuration Release \
      -sdk iphoneos \
      -derivedDataPath derived_data \
      BUILD_LIBRARY_FOR_DISTRIBUTION=YES 
    ;
    mkdir build/devices
    ;
    cp -r derived_data/Build/Products/Release-iphoneos/YourUniversalFramework.framework build/devices
    ;
    xcodebuild clean build \
      -project YourUniversalFramework.xcodeproj \
      -scheme YourUniversalFramework \
      -configuration Release \
      -sdk iphonesimulator \
      -derivedDataPath derived_data \
      BUILD_LIBRARY_FOR_DISTRIBUTION=YES
    ;
    mkdir build/simulator
    ;
    cp -r derived_data/Build/Products/Release-iphonesimulator/ build/simulator/
    ;
    mkdir build/universal
    ;
    cp -r build/devices/YourUniversalFramework.framework build/universal/
    ;
    lipo -create \
      build/simulator/YourUniversalFramework.framework/YourUniversalFramework \
      build/devices/YourUniversalFramework.framework/YourUniversalFramework \
      -output build/universal/YourUniversalFramework.framework/YourUniversalFramework
    ;
    cp -r \
    build/simulator/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/* \
    build/universal/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/YourUniversalFramework

.xcworkspace 项目的命令/脚本

mkdir build
    ;
    xcodebuild clean build \
      -workspace YourUniversalFramework.xcworkspace \
      -scheme YourUniversalFramework \
      -configuration Release \
      -sdk iphoneos \
      -derivedDataPath derived_data \
      BUILD_LIBRARY_FOR_DISTRIBUTION=YES 
    ;
    mkdir build/devices
    ;
    cp -r derived_data/Build/Products/Release-iphoneos/YourUniversalFramework.framework build/devices
    ;
    xcodebuild clean build \
      -workspace YourUniversalFramework.xcworkspace \
      -scheme YourUniversalFramework \
      -configuration Release \
      -sdk iphonesimulator \
      -derivedDataPath derived_data \
      BUILD_LIBRARY_FOR_DISTRIBUTION=YES
    ;
    mkdir build/simulator
    ;
    cp -r derived_data/Build/Products/Release-iphonesimulator/ build/simulator/
    ;
    mkdir build/universal
    ;
    cp -r build/devices/YourUniversalFramework.framework build/universal/
    ;
    lipo -create \
      build/simulator/YourUniversalFramework.framework/YourUniversalFramework \
      build/devices/YourUniversalFramework.framework/YourUniversalFramework \
      -output build/universal/YourUniversalFramework.framework/YourUniversalFramework
    ;
    cp -r \
    build/simulator/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/* \
    build/universal/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/YourUniversalFramework