Xcode – Run Script


Xcode will execute the script after compilation and before installing the app

1、 New script

Xcode - Run Script

New Run Script Phase

Add code in the red box below

Xcode - Run Script

Run Script

>>Common xocde variables

  • BUILD_ Root – compile root path
  • Srcroot – project root
  • TARGET_ Name – target name

>>How to view more variables

Xcode - Run Script

Build Setting

All variables in the list can be used. The use method is to convert English letters to uppercase, and then divide words with underscores

For example, “build active architecture only”, the variable can be represented by ${build_active_architecture_only} in the shell

>>How to add variables by yourself

Xcode - Run Script

Add User-Defined Setting

Xcode - Run Script

User-Defined Setting

The following example code shows how variables are referenced in the code


echo "Prodcut Path ${BUILD_ROOT}"

#Compilation environment judgment
if ${DEBUG}

#Create a variable

#--------- example 1: create xcframework -------- 
xcrun xcodebuild -create-xcframework \
-framework $environment-iphoneos/$framework_name.framework \
-framework $environment-iphonesimulator/$framework_name.framework \
-output ${SRCROOT}/output/$framework_name.xcframework
#---------------- example 1 - end---------------------

#--------- example 2 - create framework --------
lipo -create $environment-iphoneos/$framework_name.framework/$framework_name \
$environment-iphonesimulator/$framework_name.framework/$framework_name \
-output $framework_name;

#Copy The framework file to the current path
cp -r $environment-iphoneos/$framework_name.framework ./
#Put the synthesized file in the In framework
cp -r $framework_name $framework_name.framework/; 
rm $framework_name;

#CP - R copy all files in the current directory to the target directory
cp -r $framework_name.framework ${SRCROOT}/output
#---------------- example 2 - end---------------------

2、 Modification Plist file

Use the plistbuddy tool, which is the Mac’s own parsing tool

>>Plistbuddy common instructions

  • /usr/libexec/PlistBuddy --help-View help
  • Add – add a field. Adding a field that has already been added will result in an error
  • Set – sets a value for the added field
  • Print – prints the corresponding value
  • Merge – merge plist files
  • Delete – deletes the corresponding value

>>Plistbuddy example analysis

   /Usr / libexec / plistbuddy is the path of plistbuddy and the corresponding execution program
  @Param - C fixed parameter
  @Param add add instruction. For other instructions, see -- help
  @Add a dictionary whose key is person under the param person dict directory
  @param info. Plist is the plist file of the operation. If it is not in the current directory, it needs to be preceded by a path

/usr/libexec/PlistBuddy -c 'Add: Person dict' info.plist

In the above instructionAdd: Person dictIs to add a dictionary whose key is person

  • If there are more subdirectories, they are separated by: signs. If there are arrays, they are represented by numerical indexes::CFBundleURLTypes:0:CFBundleURLName
  • Currently supported types: string / array / dict / bool / real / integer / date / data; More types visible — help
#---------------- example: modify info Plist file-------- 

# lws apikey 
/Usr / libexec / plistbuddy - C "set: apikey" $apikey "" "$plistpath" # plispath with "$" on both sides to prevent spaces on the path
# bundle identify
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier "$bundle_id"" "$plistPath" 
#FB jump back to app scheme
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:0:CFBundleURLName \"fb-"${bundle_id}"\"" "$plistPath" 
#AMZN jump back to app scheme
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:1:CFBundleURLName \"amzn-"${bundle_id}"\"" "$plistPath"
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:1:CFBundleURLSchemes:0 \"amzn-"${bundle_id}"\"" "$plistPath" 
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $nowtime" "$plistPath"
#/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${MARKETING_VERSION}" "$plistPath"
#---------------- example - end---------------------

>>View in Xcode Plist file

Xcode open Plist files are displayed in the form of property list by default. If you want to view specific keys, you need to select source code

Xcode - Run Script


Recommended Today

JVM + GC parsing (premise knowledge concatenation)

Premise preparation JVM GC garbage collection JVM virtual machine monitoring, tuning and troubleshooting Tomcat and microservice optimization 1. Premise review 1.1. JVM memory structure 1.1.1、 JVM Architecture Overview The gray part in the figure isThread private, there is almost no garbage collectionOrange partThread sharing, the main place where garbage recycling occurs What is the class […]