Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Script - Get Bundle ID from build settings instead of info.plist

Tags:

xcode

receigen

I'm using Receigen for Apple receipt checking. I have integrated a script on my build process that generates the appropriate files for my project:

    # Receigen binary
RECEIGEN="/Applications/Receigen.app/Contents/MacOS/Receigen"

# Extract Info.plist information
INPUT="$INFOPLIST_FILE"
BUNDLE_ID=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$INPUT"`
BUNDLE_VERSION=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INPUT"`

# Expand information if needed
EXPANDED_BUNDLE_ID=`eval "echo $BUNDLE_ID"`
EXPANDED_BUNDLE_VERSION=`eval "echo $BUNDLE_VERSION"`

# Make sure the destination directory exists
mkdir -p "$DERIVED_FILES_DIR"
HEADER="$DERIVED_FILES_DIR/receiptCheck.h"

# Check if the generation is needed
if [ -e "$HEADER" ]; then
SKIP=`grep -q "$EXPANDED_BUNDLE_ID" "$HEADER" && grep -q "$EXPANDED_BUNDLE_VERSION" "$HEADER" && echo "YES"`
fi

# Generate the header file if needed
if [ "x$SKIP" = "x" ]; then
"$RECEIGEN" --identifier "$EXPANDED_BUNDLE_ID" --version "$EXPANDED_BUNDLE_VERSION" --failure 'exitwith173' --success 'runapplication' --os osx > "$HEADER"
fi

The problem with Xcode 7 is with this line:

BUNDLE_ID=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$INPUT"`

Because the BundleID on the new Xcode is on the build settings instead of Info.plist I believe the key on the build settings is $(PRODUCT_BUNDLE_IDENTIFIER)

Is there a way to extract the Bundle Id from the build settings on the script ?

like image 734
the Reverend Avatar asked Sep 07 '15 21:09

the Reverend


People also ask

How do I find my bundle ID Xcode?

Open you project with XCode, select the top project item in the project navigator at the left. Then select TARGETS -> General. Bundle Identifier is found under Identity.

What is $( Product_bundle_identifier?

The new build setting Product Bundle Identifier (PRODUCT_BUNDLE_IDENTIFIER) is the recommended place to set the Bundle Identifier for a target. The target's Info. plist should be configured to use this build setting by referencing it as $(PRODUCT_BUNDLE_IDENTIFIER) in the value for the CFBundleIdentifier key.

How do I change my product bundle identifier?

Under Targets > Build settings, scroll to Packaging. Change your Product name to the desired name & Product bundle identifier to the new one. Once you do this, automatically your project display name & bundle id changes to the new one in General tab.

Can I change bundle identifier in Xcode?

By default, Xcode sets the bundle identifier to the bundle/company identifier that you set during project creation + project name. This is similar to what you see in the Project > Summary screen. But you can change this in the Project > Info screen.


2 Answers

You can just use the $PRODUCT_BUNDLE_IDENTIFIER instead of hardcoding the bundle id:

EXPANDED_BUNDLE_ID=$PRODUCT_BUNDLE_IDENTIFIER

(Note that there are no parentheses around PRODUCT_BUNDLE_IDENTIFIER).

You can then delete the line that starts with BUNDLE_ID= because it is no longer necessary.

like image 91
Thorsten Avatar answered Oct 16 '22 06:10

Thorsten


It's very easy :

BUNDLE_ID= xcodebuild -showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER

echo $BUNDLE_ID

like image 33
Abouluadi Avatar answered Oct 16 '22 07:10

Abouluadi