From 76b585d130c6b0a62a5625e32ced6fceb883754e Mon Sep 17 00:00:00 2001 From: Mirko Galimberti Date: Sat, 23 May 2020 11:39:53 +0200 Subject: [PATCH] Add framework thinner for iOS Apple store validation --- .../frameworks_thinner.sh | 31 +++++++++++++ .../project.pbxproj | 46 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/frameworks_thinner.sh diff --git a/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/frameworks_thinner.sh b/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/frameworks_thinner.sh new file mode 100755 index 000000000..a011775f1 --- /dev/null +++ b/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/frameworks_thinner.sh @@ -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 diff --git a/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/{{ cookiecutter.project_name }}.xcodeproj/project.pbxproj b/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/{{ cookiecutter.project_name }}.xcodeproj/project.pbxproj index 87e39bf95..36b006ab8 100755 --- a/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/{{ cookiecutter.project_name }}.xcodeproj/project.pbxproj +++ b/kivy_ios/tools/templates/{{ cookiecutter.project_name }}-ios/{{ cookiecutter.project_name }}.xcodeproj/project.pbxproj @@ -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 = ""; }; 1D6058910D05DD3D006BFB54 /* {{ cookiecutter.project_name }}.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = {{ cookiecutter.project_name }}.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -48,6 +62,7 @@ 59738AD91A8E62D6001B2C0C /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@2x.png"; path = "LaunchImages/Default@2x.png"; sourceTree = ""; }; 59738ADA1A8E62D6001B2C0C /* Default@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@3x.png"; path = "LaunchImages/Default@3x.png"; sourceTree = ""; }; 59994E3A148E85C800863906 /* YourApp */ = {isa = PBXFileReference; lastKnownFileType = folder; path = YourApp; sourceTree = ""; }; + 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 = ""; }; /* End PBXFileReference section */ @@ -82,6 +97,7 @@ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( + ACAA5ADA24791C3C00C86143 /* Scripts */, 080E96DDFE201D6D7F000001 /* Classes */, 29B97315FDCFA39411CA2CEA /* Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, @@ -130,6 +146,14 @@ name = Frameworks; sourceTree = ""; }; + ACAA5ADA24791C3C00C86143 /* Scripts */ = { + isa = PBXGroup; + children = ( + ACAA5ADB24791C6100C86143 /* frameworks_thinner.sh */, + ); + path = Scripts; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -143,6 +167,8 @@ 1D60588D0D05DD3D006BFB54 /* Resources */, 1D60588E0D05DD3D006BFB54 /* Sources */, 1D60588F0D05DD3D006BFB54 /* Frameworks */, + EF5745029C423687AC1203A1 /* Embed Frameworks */, + ACAA5AD924791BF300C86143 /* ShellScript */, ); buildRules = ( ); @@ -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;