设置App的编译阶段 (Build Phases)
<h1>设置App的编译阶段 (Build Phases) (共3步)</h1>
<p>1 在目标App的编译阶段(Build Phases)中,添加一个脚本运行阶段 (Run Script Phase)。
<img src="images/BuildPhases配置1.png" alt="" />
2 请确认该脚本运行阶段放置在所有阶段的最后。
<img src="images/BuildPhases配置2.png" alt="" />
3 将下面代码段的内容粘贴到新增的脚本运行阶段中。
<strong>在原有的脚本中,增强日志输入,以便于Debug</strong></p>
<pre><code># Output Log to /tmp/*_BSSDKRunScript.log
exec &gt; /tmp/${PROJECT_NAME}_${TARGET_NAME}_BSSDKRunScript.log 2&gt;&amp;1
echo &quot;Architectures trimming begins&quot;
APP_PATH=&quot;${TARGET_BUILD_DIR}/${WRAPPER_NAME}&quot;
echo &quot;APP_PATH:${APP_PATH}&quot;
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find &quot;$APP_PATH&quot; -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read &quot;$FRAMEWORK/Info.plist&quot; CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH=&quot;$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME&quot;
echo &quot;Executable is $FRAMEWORK_EXECUTABLE_PATH&quot;
EXTRACTED_ARCHS=()
echo &quot;Architectures to keep:${ARCHS}&quot;
for ARCH in $ARCHS
do
echo &quot;Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME&quot;
lipo -extract &quot;$ARCH&quot; &quot;$FRAMEWORK_EXECUTABLE_PATH&quot; -o &quot;$FRAMEWORK_EXECUTABLE_PATH-$ARCH&quot;
echo &quot;$ARCH:$FRAMEWORK_EXECUTABLE_PATH-$ARCH&quot;
EXTRACTED_ARCHS+=(&quot;$FRAMEWORK_EXECUTABLE_PATH-$ARCH&quot;)
done
echo &quot;EXTRACTED_ARCHS:&quot;
echo &quot;${EXTRACTED_ARCHS}&quot;
echo &quot;Merging extracted architectures: ${ARCHS}&quot;
lipo -o &quot;$FRAMEWORK_EXECUTABLE_PATH-merged&quot; -create &quot;${EXTRACTED_ARCHS[@]}&quot;
echo &quot;Remove ${EXTRACTED_ARCHS[@]}&quot;
rm &quot;${EXTRACTED_ARCHS[@]}&quot;
echo &quot;Replacing original executable with thinned version&quot;
echo &quot;Remove $FRAMEWORK_EXECUTABLE_PATH&quot;
rm &quot;$FRAMEWORK_EXECUTABLE_PATH&quot;
mv &quot;$FRAMEWORK_EXECUTABLE_PATH-merged&quot; &quot;$FRAMEWORK_EXECUTABLE_PATH&quot;
done
if [ $? -eq 0 ]; then
echo &quot;Architectures trimming is completed!&quot;
else
echo &quot;Architectures trimming is failed!!!&quot;
fi</code></pre>
<p>4 该步骤设置结束,用于在生成App时,把非对应CPU架构的Binary给清掉,以减小<strong>App</strong>的大小。</p>