我已使用Kotlin / Native为arm64和x86_64架构编译了mylib.framework
,并在常规标签中使用Embedded Binaries
嵌入了arm64架构。在测试目标中,我使用Link Binary With Libraries
引用了x86_64框架。设备的存档和编译工作良好,但是用于测试目标对arm64框架的引用的编译过程。在测试目标的常规标签中,我没有Embedded Binaries
部分。
如何告诉Xcode使用arm64框架进行设备和归档构建以及测试目标使用x86_64框架?
答案 0 :(得分:0)
首先(如果尚未安装),则应将Gradle插件用于Kotlin-Native / Kotlin-Multiplatform。您的目标的主要优点是,有了正确的目标依赖项,它可以为您提供许多任务,每个任务恰好满足您的一种需求:
$ sh -c ". ./gradlew tasks"
...
compileDebugIos_arm64KotlinNative - Compiles Kotlin/Native source set 'main' into a framework
compileDebugIos_x64KotlinNative - Compiles Kotlin/Native source set 'main' into a framework
compileReleaseIos_arm64KotlinNative - Compiles Kotlin/Native source set 'main' into a framework
compileReleaseIos_x64KotlinNative - Compiles Kotlin/Native source set 'main' into a framework
然后,您可以在构建设置“用户定义的部分”中为每个任务的每个目标声明不同的值,如下所示:
最后一步是通过动态使用合适的任务名称,在Xcode-Project中添加一个编译阶段,以完全根据给定上下文的需要编译Kotlin代码:
...
sh -c ". ./gradlew $KONAN_TASK"
...
This tutorial (https://www.raywenderlich.com/7357-ios-app-with-kotlin-native-getting-started)提供了更多详细信息和示例代码。
答案 1 :(得分:0)
现在,我在“构建阶段”标签中使用Xcode的“运行脚本”,并在网络上找到以下内容:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# 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"
done