Setting PRODUCT_NAME for CocoaPods project via shell script - ios

I have a project that uses cocoa pods.
I couldn't set the PRODUCT_NAME in xcodebuild it always leads to compile time error.
/usr/bin/xcodebuild
-scheme $Scheme -workspace $WorkSpaceOfProject
-configuration Debug clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity"
"PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier"
"PROVISIONING_PROFILE=$ProvisioningProfileIdentity" "PRODUCT_NAME
=$Appname"
unknown:0: error: underlying Objective-C module 'Appname' not found
If I remove the PRODUCT_NAME from the above script, then it compiles successfully but unfortunately I have to set the app name via script
I tried setting -xcconfig as somebody suggested , it also didn't work out.
How can I change the app name through script but at the same time compile the app with cocoa pods?
If I compile it using the project file instead of workspace it executes without any problem. Here is the script:
/usr/bin/xcodebuild -target $Target -project $ProjectFilePathAbsolute
-configuration Debug clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_NAME =$Appname"
"PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier"
"PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
But I have to compile with workspace because I am using cocoapods.
Any suggestions are highly welcome.

I solved the above issue by using PlistBuddy and in the xcodebuild command I didn't use PRODUCT_NAME
Here is the script that I used
/usr/libexec/PlistBuddy -c "Set :CFBundleName test" info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName test" info.plist
/usr/bin/xcodebuild -scheme $Scheme -workspace $WorkSpaceOfProject
-configuration Debug clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity"
"PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier"
"PROVISIONING_PROFILE=$ProvisioningProfileIdentity" "PRODUCT_NAME
=$Appname"

Related

Xcode 8.3.2 build script - Specified application doesn't exist or isn't a bundle directory

I have a problem with xcode build script, hope you can help.
In older Xcode this script works well but now after upgraded the xcode always failed.
configuration='Release'
provision="haithngn_release.mobileprovision"
identity="iPhone Distribution: HAITHNGN (TEAMID)"
sdk="iphoneos"
scheme="Mobile"
configuration=$1
version=$2
build=$3
output="$PWD/build/$scheme.$version.$build.$configuration.ipa"
PLIST_PATH="./Mobile/Platforms/ios/Application/"
PLIST_FILE="Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "$PLIST_PATH/$PLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $version.$build" "$PLIST_PATH/$PLIST_FILE"
echo "Cleaning up old build..."
rm -Rf "$PWD/build/$configuration-$sdk"
echo "Building $scheme, using $configuration configuration, provisioning = $provision"
xcodebuild -sdk "$sdk" -scheme "$scheme" -configuration "$configuration" clean OBJROOT="$PWD/build" SYMROOT="$PWD/build" ONLY_ACTIVE_ARCH=NO
xcodebuild -sdk "$sdk" -scheme "$scheme" -configuration "$configuration" OBJROOT="$PWD/build" SYMROOT="$PWD/build" ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="$identity"
xcodebuild -exportArchive -sdk "$sdk" "$PWD/build/$configuration-$sdk/$scheme.app" "$PWD/build/$configuration-$sdk/$scheme.ipa" "$provision"
cp "$PWD/build/$configuration-$sdk/$scheme.ipa" "$output"
Terminal Logs:
xcodebuild: error: The flag -exportPath is required when specifying
-exportArchive. xcodebuild: error: The flag -exportOptionsPlist is required when specifying -exportArchive. xcodebuild: error: The flag
-archivePath is required when specifying -exportArchive.
XCode version 8.3.2
Starting from Xcode 8.3, you should use xcodebuild -exportArchive instead of xcrun (see there) or apparently, just zipping the App works as well (see there).
Otherwise, you might want to use Fastlane Gym.

Old path persists in XCode framework build

The following script is part of an aggregate target build phase that is supposed to be used to combine simulator and device targets into one universal framework build. The build originated from this SO answer.
set -e
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
######################
# Build Frameworks
######################
echo "PROJECT_NAME: ${PROJECT_NAME}"
echo "CONFIGURATION: ${CONFIGURATION}"
echo "BUILD_DIR: ${BUILD_DIR}"
echo "SIMULATOR_LIBRARY_PATH: ${SIMULATOR_LIBRARY_PATH}"
echo "DEVICE_LIBRARY_PATH: ${DEVICE_LIBRARY_PATH}"
echo "UNIVERSAL_LIBRARY_DIR: ${UNIVERSAL_LIBRARY_DIR}"
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -target ${PROJECT_NAME} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
Here is the first error I get when executing this script:
PROJECT_NAME: My-project_Framework
CONFIGURATION: Debug
BUILD_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products
SIMULATOR_LIBRARY_PATH: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphonesimulator/My-project_Framework.framework
DEVICE_LIBRARY_PATH: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphoneos/My-project_Framework.framework
UNIVERSAL_LIBRARY_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphoneuniversal
Build settings from command line:
CONFIGURATION_BUILD_DIR = /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphonesimulator
SDKROOT = iphonesimulator8.1
=== CLEAN TARGET My-project_Framework OF PROJECT My-project_Framework WITH CONFIGURATION Debug ===
Check dependencies
Create product structure
/bin/mkdir -p /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphonesimulator/My-project_iOS.framework
Clean.Remove clean /Volumes/local\ my-project/my-project/ios/Framework/build/My-project_Framework.build/Debug-iphonesimulator/My-project_Framework.build
builtin-rm -rf /Volumes/local\ my-project/my-project/ios/Framework/build/My-project_Framework.build/Debug-iphonesimulator/My-project_Framework.build
Clean.Remove clean /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphonesimulator/My-project_iOS.framework
builtin-rm -rf /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphonesimulator/My-project_iOS.framework
** CLEAN SUCCEEDED **
=== BUILD TARGET My-project_Framework OF PROJECT My-project_Framework WITH CONFIGURATION Debug ===
Check dependencies
error: Unable to create directory: /Volumes/local my-project/my-project/ios/Framework/build (Permission denied)
Now here is the problem
This mount point, /Volumes/local my-project (with a space) has been replaced with /Volumes/localmy-project (without a space). Yet XCode still seems to have the old path somewhere.
Here's what I did to try rip it out of XCode (version 6.1.1):
Added the echo calls to the script to show all the command line inputs to xcodebuild. As you can see this path doesn't come in from the command line call.
Cleaned all targets (Choose each target, Product->Clean).
Checked all the files included in this framework project - all of them have location set to Relative to Project in the inspector.
Restarted XCode.
Restarted the Mac.
Checked project.pbxproj and all other XML files found in the project package contents - no absolute path to be found.
Checked the target in the inspector - its location is absolute (cannot be changed) and correctly points to the new path (/Volumes/localmy-project/...)
Went into the organizer and went Projects->My-Project->Derived Data->Delete.
After all this, the error still persists. So - where the hell is XCode getting this old path from?
Update
I've added the following echos to show a few more build environment variables according to #Louis Tur:
BUILT_PRODUCTS_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-Project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphoneos
CACHE_ROOT: /var/folders/w1/v31fpgnd7sl0yp5ctqjgsxsh0000gn/C/com.apple.DeveloperTools/6.1.1-6A2008a/Xcode
CONFIGURATION_BUILD_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-Project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphoneos
CONFIGURATION_TEMP_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-Project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-Project_Framework.build/Debug-iphoneos
SYMROOT: /Users/foouser/Library/Developer/Xcode/DerivedData/My-Project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products
Update2 - Now with even more echos!
DEPLOYMENT_LOCATION: NO
DERIVED_FILE_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build/DerivedSources
DSTROOT: /tmp/My-project_Framework.dst
INSTALL_DIR: /tmp/My-project_Framework.dst
INSTALL_PATH:
OBJECT_FILE_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build/Objects
OBJECT_FILE_DIR_normal: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build/Objects-normal
OBJECT_FILE_DIR_debug:
OBJROOT: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates
PROJECT_TEMP_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build
REZ_COLLECTOR_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build/ResourceManagerResources
REZ_OBJECTS_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build/ResourceManagerResources/Objects
SHARED_PRECOMPS_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/PrecompiledHeaders
SRCROOT: /Volumes/localmy-project/my-project/ios/Framework
TARGET_BUILD_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Products/Debug-iphoneos
TARGET_TEMP_DIR: /Users/foouser/Library/Developer/Xcode/DerivedData/My-project_Framework-fjaslxiqhnitqxdksjbcxyuugfpk/Build/Intermediates/My-project_Framework.build/Debug-iphoneos/My-project_Framework_Universal.build
Still none of these point to the old path then..
I encountered this problem and solved by reset the Location of Derived data folder in Xcode preference.
After setting, I quit Xcode and relaunch again. It solved.
I still don't know how that old path is coming in, but I've found a workaround that works for me: I can force the correct DerivedData path by using xcodebuild the following way (which replaces the old calls in the script):
xcodebuild -scheme ${PROJECT_NAME} -derivedDataPath ${BUILD_DIR}/../../ -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
xcodebuild -scheme ${PROJECT_NAME} -derivedDataPath ${BUILD_DIR}/../../ -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
If anyone has an idea where the old path could still persist, please let me know.

xcodebuild - build all targets using command line

I'm using the command line to build all the targets in my project.
I have 3 targets in my project but the build file(.app) is getting created for one target.
Below is script
CONFIG="Ad Hoc"
SDK="iphoneos"
xcodebuild -alltargets -sdk "$SDK" -configuration "$CONFIG"
xcodebuild -project projectname.xcodeproj -alltargets

Creating Static Library from a workspace

I managed to get static libraries working and its all fine. Now that I have moved onto the proper library I want to create Im having issues. Im using cocoapods to import other files and it creates a workspace. Now the script I have for compiling no longer works and my assumption is because I am working in a framework now. I have been googling for hours trying to get an answer but all the things I have found only relate to turning a single project into a library
My questions are:
1) Is it possible to combine a workspace into one single library?
2) should I be trying to create a framework instead?
3) Is it just my script that isnt right?
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
also tried this
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -workspace T5Pusher.xcworkspace -scheme "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -workspace T5Pusher.xcworkspace -scheme "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
The errors I get are
** BUILD FAILED **
The following build commands failed:
Libtool build/PusherTest.build/Release-iphoneos/PusherTest.build/Objects- normal/armv7/libPusherTest.a normal armv7
Libtool build/PusherTest.build/Release-iphoneos/PusherTest.build/Objects-normal/armv7s/libPusherTest.a normal armv7s
(2 failures)
lipo: can't open input file: build/Release-iphoneos/libPusherTest.a (No such file or directory)
Showing first 200 notices only
and for the second, the build succeeds but the library (.a) files are never created so it cannot combine them
I have found the solution. You have to use the command:
pod install --no-integrate
when installing the pod. This will not create a workspace and allow the use of the script
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
Then to set the config file for pods:
-Go to project editor -> info -> configuration
-Set the target to use pods.xconfig file for debug and release
I was having the same issue myself and found that if I specified the output directories and then told lipo to look there then it worked while still letting me use the workspace. The may be different in Xcode 5 but when I use it as a custom build phase then it works without specifying the output directories and I only have to direct lipo to ${BUILD_DIR} to find the generated files.
$XCODEBUILD -project T5Pusher.xcodeproj \
-target "T5Pusher" \
-sdk "iphoneos" \
-configuration "Release"
OBJROOT=${env_variable_to_some_directory}/Obj.root \
SYMROOT=${env_variable_to_some_directory}/Sym.root \
DSTROOT=${env_variable_to_some_directory}/Dst.root \
clean build

xcodebuild PLATFORM_NAME always == iphoneos

I am trying to build Xcode project from command line, using iphonesimulator as SDK. Here is the command line:
xcodebuild -scheme SchemeName -configuration Debug -sdk iphonesimulator PLATFORM_NAME=iphonesimulator clean build
However, when I add a post-build action in Xcode like:
echo "PLATFORM_NAME: ${PLATFORM_NAME}"
it always outputs "PLATFORM_NAME: iphoneos" and not iphonesimulator.
Is this a bug, or there is something wrong in my build configuration? Thanks

Resources