web-dev-qa-db-ja.com

Xcode 10のFat Frameworkスクリプト?

私は、FATバイナリフレームワークを作成するために、このスクリプトを私のスキームのアーカイブの後処理で使用しました。シミュレータと実際のデバイスで動作するもの。

https://Gist.github.com/gauravkeshre/eabb2a13ef6d673fadec84ca60b56b05

Xcode 10で動作するように変換する方法を知っている人はいますか?

レガシービルドシステムを使用するとエラーは修正されますが、私はそれを頼りにしたくありません。

スクリプト自体は次のとおりです。

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1

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

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

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

echo "Building for iPhoneSimulator"
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS' ONLY_ACTIVE_Arch=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

# Step 1. Copy the framework structure (from iphoneos build) to the universal folder
echo "Copying to output folder"
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 2. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_Swift_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_Swift_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_Swift_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule"
fi

# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "Combining executables"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

# Step 4. Create universal binaries for embedded frameworks
for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks" ); do
BINARY_NAME="${SUB_FRAMEWORK%.*}"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
done

# Step 5. Convenience step to copy the framework to the project's directory
echo "Copying to project dir"
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${PROJECT_DIR}"

open "${PROJECT_DIR}"

fi

** BUILD SUCCEEDED **の後の出力ログのエラー:

Copying to output folder
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-iphonesimulator/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/.: unable to copy extended attributes to /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/i386.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/x86_64.swiftdoc: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/x86_64.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/i386.swiftdoc: No such file or directory

その後:

fatal error: /Applications/Xcode 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't create temporary output file: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/ContactAtOnceMessaging.lipo (No such file or directory)
ls: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Frameworks: No such file or directory
Copying to project dir
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework: No such file or directory

.frameworkフォルダーがないため、Release-universalフォルダーに入ると、最初のパスは不安定になります。代わりに、フレームワークのcontentsがあります。

12
Aaron Bratcher

何も変更する必要はありません。フレームワークターゲットのビルド設定でskip_installをNOに設定するだけです。また、アーカイブする前に、$ {PROJECT_DIR}から.frameworkを削除します。

それでもうまくいかない場合は、$ {PROJECT_NAME} _archive.logが間違っていたという内容で質問を編集してください。

編集:また、xcode 10でレガシーシステムを使用してビルドしてみてください。ファイル->ワークスペース設定->システムのビルド

編集2:何らかの理由で、Xcode 10のポストアクションbashスクリプトは、以前のXcodeバージョンとは異なる動作をします。特に次の行:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

Xcode 10では、.frameworkの内容を$ {UNIVERSAL_OUTPUTFOLDER}にコピーしますが、Xcode 9.3では.framework全体をフォルダーにコピーします。

この行を次のように変更すると:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/" "${UNIVERSAL_OUTPUTFOLDER}"

スクリプトはXcode 10で正常に動作します。

私が使用したスクリプト:

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1

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

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

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
#mkdir -p "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework" 

echo "Building for iPhoneSimulator"
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS' ONLY_ACTIVE_Arch=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

# Step 1. Copy the framework structure (from iphoneos build) to the universal folder
echo "Copying to output folder"
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/" "${UNIVERSAL_OUTPUTFOLDER}"

# Step 2. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_Swift_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_Swift_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_Swift_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule"
fi

# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "Combining executables"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

echo "Combining executables end"

# Step 4. Create universal binaries for embedded frameworks
for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks" ); do
BINARY_NAME="${SUB_FRAMEWORK%.*}"
echo "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
done

# Step 5. Convenience step to copy the framework to the project's directory
echo "Copying to project dir"
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${PROJECT_DIR}"

open "${PROJECT_DIR}"

fi
18
AlexM

Xcode 10.1(2019年2月)

私は Gistを作成しました Xcode 10のFatフレームワークとCocoapodsのバイナリフレームワークの問題をどのように解決するかについての簡単な説明を付けました。

2
atereshkov

https://forums.developer.Apple.com/thread/10958 からスクリプトを変更しましたが、Xcode 10.1でうまく機能します

最後は script。 です

0
xuzepei