Skip to content

Commit

Permalink
Add framework thinner for iOS Apple store validation
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed May 23, 2020
1 parent df7e12d commit 76b585d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# (An edited version of http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-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=()
# We check the output of "lipo -info" cause not all the frameworks are Universal (Ex: some frameworks installed via Pods)
if [[ $(lipo -info "$FRAMEWORK_EXECUTABLE_PATH") != Non-fat* ]] ;
then
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"
fi
done
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
59994E3B148E85C800863906 /* YourApp in Resources */ = {isa = PBXBuildFile; fileRef = 59994E3A148E85C800863906 /* YourApp */; };
/* End PBXBuildFile section */


/* Begin PBXCopyFilesBuildPhase section */
EF5745029C423687AC1203A1 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01532DA9137C099F0076F6BF /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
1D6058910D05DD3D006BFB54 /* {{ cookiecutter.project_name }}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = {{ cookiecutter.project_name }}.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -48,6 +62,7 @@
59738AD91A8E62D6001B2C0C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "LaunchImages/[email protected]"; sourceTree = "<group>"; };
59738ADA1A8E62D6001B2C0C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "LaunchImages/[email protected]"; sourceTree = "<group>"; };
59994E3A148E85C800863906 /* YourApp */ = {isa = PBXFileReference; lastKnownFileType = folder; path = YourApp; sourceTree = "<group>"; };
ACAA5ADB24791C6100C86143 /* frameworks_thinner.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = frameworks_thinner.sh; sourceTree = SOURCE_ROOT; };
8D1107310486CEB800E47090 /* {{ cookiecutter.project_name }}-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "{{ cookiecutter.project_name }}-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -82,6 +97,7 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
ACAA5ADA24791C3C00C86143 /* Scripts */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
Expand Down Expand Up @@ -130,6 +146,14 @@
name = Frameworks;
sourceTree = "<group>";
};
ACAA5ADA24791C3C00C86143 /* Scripts */ = {
isa = PBXGroup;
children = (
ACAA5ADB24791C6100C86143 /* frameworks_thinner.sh */,
);
path = Scripts;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -143,6 +167,8 @@
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
EF5745029C423687AC1203A1 /* Embed Frameworks */,
ACAA5AD924791BF300C86143 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -254,6 +280,26 @@
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
ACAA5AD924791BF300C86143 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$PROJECT_DIR\"/frameworks_thinner.sh\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
1D60588E0D05DD3D006BFB54 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down

0 comments on commit 76b585d

Please sign in to comment.