2017-07-19 49 views
1

我正在開發一個依賴於Alamofire的小型Swift框架。我使用它作爲屬於同一工作區的應用程序的嵌入式框架,並且完美地工作。取決於pod的Swift通用框架

問題出現在我想要構建一個具有聚合目標的通用框架時。然後,當執行腳本生成框架時,它會失敗,並顯示消息No such module 'Alamofire',在我的一個源文件中提及import Alamofire

這是我Podfile:

platform :ios, '9.0' 
use_frameworks! 
inhibit_all_warnings! 

target 'FSIBackend' do 
    pod 'SwiftLint' 
    pod 'Alamofire' 
    pod 'SwiftyJSON' 
end 

這是生成框架腳本。它與不依賴豆莢其他框架,所以我認爲這是確定:

set -e 

# Setup 
FRAMEWORK_NAME="${1}" 
BUILD_DIR="${SRCROOT}/build" 
OUTPUT_DIR="${HOME}/Desktop/" 
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework" 

rm -rf "${BUILD_DIR}" 
rm -rf "${OUTPUT}" 
mkdir -p "${OUTPUT_DIR}" 

# Build 
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" 
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" 

# Copy the device version of framework to output. 
cp -r "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}" 

# Replace the framework executable within the framework with a new version created by merging the device and simulator frameworks' executables with lipo. 
lipo -create -output "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" 

# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6. 
cp -r "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule" 

# Delete build. 
rm -rf "${BUILD_DIR}" 

的問題是,我不知道如何建立我的框架取決於Alamofire。我必須爲我的框架創建一個podspec並通過CocoaPods使用它嗎?這是我第一次根據吊艙創建一個通用框架,所以我不知道我是否做了不可能的事情。

非常感謝。

+0

你可以發佈你在Aggregate target中運行的腳本嗎? –

+0

@mag_zbc完成:) – emenegro

+1

最近我也遇到了使用豆莢構建工作空間的問題。您可以嘗試將'xcodebuild -target「$ {FRAMEWORK_NAME}''更改爲'xcodebuild -workspace」YourWorkspace.xcworkspace「-scheme YourScheme' –

回答

1

最後,我可以完成它考慮@mag_zbc提供的建議,謝謝。

我不得不修改框架一代是這樣的:

set -e 

# Setup 
WORKSPACE="${1}" 
FRAMEWORK_NAME="${2}" 
BUILD_DIR="${SRCROOT}/build" 
OUTPUT_DIR="${HOME}/Desktop/" 
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework" 
CONFIGURATION="${CONFIGURATION}" 

rm -rf "${BUILD_DIR}" 
rm -rf "${OUTPUT}" 
mkdir -p "${OUTPUT_DIR}" 

# Build the framework for device and for simulator (using all needed architectures). 
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 

# Copy the device version of framework to output. 
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}" 

# Replace the framework executable within the framework with a new version created by merging the device and simulator frameworks' executables with lipo. 
lipo -create -output "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" 

# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6. 
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule" 

# Delete build. 
rm -rf "${BUILD_DIR}" 

生成後,並添加到消費者應用程序,唯一剩下要做的就是使用的CocoaPods在消費應用獲取Alamofire和SwiftyJSON 。