How to Run Xcode Project From Terminal in iOS Device? - xcode

I want to Install Xcode Project in to iOS Device thru Terminal.I know how to Build Application using xcodebuild clean install this command.I want to launch app in device.Please can any body help me in this task?
I have tried some commands which executes successfully as well but now i am getting the following error when i tried to execute the following command.
xcodebuild -target "GoldenGate" -sdk "iOS 6.1" -configuration Release
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
PROJECT="GoldenGate"
SIGNING_IDENTITY="iPhone Developer: Deepak Shukla"
PROVISIONING_PROFILE="${WORKSPACE}/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision"
ARCHIVE="$(ls -dt ~/Library/Developer/Xcode/Archives//${PROJECT}.xcarchive|head -1)"
IPA_DIR="${WORKSPACE}"
DSYM="${ARCHIVE}/dSYMs/${PROJECT}.app.dSYM"
APP="${ARCHIVE}/Products/Applications/${PROJECT}.app"
/bin/rm -f "${IPA_DIR}/${PROJECT}.ipa"
/usr/bin/xcrun -sdk iphoneos PackageApplication \
-o "${IPA_DIR}/${PROJECT}.ipa" \
-verbose "${APP}" \
-sign "${SIGNING_IDENTITY}" \
--embed "${PROVISIONING_PROFILE}"
Embedding '/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision'
/bin/rm -rf /var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision
Program /bin/rm returned 0 : []
/bin/cp -rp /E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision /var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision
Program /bin/cp returned 1 : [cp: /E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision: No such file or directory
]
error: Unable to copy '/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision' to '/var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision'
Please help me in this task.

#!/bin/sh
# build.sh
#
# Created by iOSRider on 27/01/2014.
APPLICATION_NAME=MyApp
PROJDIR=/Users/iOSRider/Desktop/MyApp
PROJECT_NAME= MyApp
TARGET_SDK="iphoneos"
PROJECT_BUILDDIR="${PROJDIR}/build/Release-iphoneos"
TARGET_TEST_NAME="MyApp"
BUILD_HISTORY_DIR="/Users/iOSRider/Desktop/MyApp"
DEVELOPPER_NAME="iPhone Distribution: iOSRider India Limited (R8UAKS2M7L)"
PROVISONNING_PROFILE="/Users/iOSRider/Desktop/MyApp/iOS.mobileprovision"
# compile project echo Building Project cd "${PROJDIR}" xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release
#Check if build succeeded
if [ $? != 0 ] then exit 1 fi
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPPER_NAME}" --embed "${PROVISONNING_PROFILE}"

Related

How can I stop prints of xcodebuild to consol in macOS

I want make xcodebuild in Terminal without those extra long long prints, for that goal I am using quiet code, but it seems not working! How can I stop prints?
xcodebuild archive \
-scheme Test \
-configuration Release \
//some other codes ...
-SKIP_INSTALL=NO \
-BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
-quiet=YES

Shell script not executing till end , Stops execution in between no error shown

I have the below attached shell script , it is not executing till the end of the script its stops execution at comment "#Execution stops here" no error is shown. Basically this script is used to build an ios ionic application and generate ipa and upload to store
#!/bin/bash
set -e
set -u
ITC_PASSWORD="myitunes password"
ITC_USER="myitunes username"
echo "Removing IOS platform..."
ionic cordova platform rm ios
echo "Adding IOS platform..."
ionic cordova platform add ios --no-resources
echo "Installing dependencies"
npm install
cd platforms/ios
echo "Installing pods"
pod install
yarn
cd ../..
echo "Cordova build running"
ionic cordova build ios --device --prod --release -- --provisioningProfile="5xxxxx-xxxa-4eeee-9f49-xxxxxxx" --developmentTeam="xxxxxxx" --codeSignIdentity="iPhone Distribution" --packageType="app-store" --codeSignStyle="manual"
echo "Adding Push notification entitlement"
if grep -q aps-environment platforms/ios/MyIosApp/Resources/MyIosApp.entitlements; then
echo "Push notification entitlement already exists."
else
echo "Push notification entitlement added."
sed -i '' '/^[[:space:]]*<dict>/a\'$'\n''\'$'\t''<key>aps-environment<\/key>\'$'\n''\'$'\t''<string>development<\/string>\'$'\n''' platforms/ios/MyIosApp/Resources/MyIosApp.entitlements
fi
echo "Adding Iad Orientation "
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :UISupportedInterfaceOrientations array
Add :UISupportedInterfaceOrientations: string UIInterfaceOrientationPortrait
Add :UISupportedInterfaceOrientations: string UIInterfaceOrientationPortraitUpsideDown
Add :UISupportedInterfaceOrientations~ipad array
Add :UISupportedInterfaceOrientations~ipad: string UIInterfaceOrientationPortrait
Add :UISupportedInterfaceOrientations~ipad: string UIInterfaceOrientationPortraitUpsideDown
Add :UISupportedInterfaceOrientations~ipad: string UIInterfaceOrientationLandscapeLeft
Add :UISupportedInterfaceOrientations~ipad: string UIInterfaceOrientationLandscapeRight
EOF
while read line
do
/usr/libexec/PlistBuddy -c "$line" $PLIST
done
#true
Execution stops here
Below code is not executing
cd platforms/ios
echo "Building app"
xcodebuild -workspace MyIosApp.xcworkspace -scheme MyIosApp -sdk iphoneos -configuration AppStoreDistribution archive -allowProvisioningUpdates -archivePath $PWD/build/MyIosApp.xcarchive
echo "Exporting Ipa"
xcodebuild -exportArchive -archivePath $PWD/build/MyIosApp.xcarchive -exportOptionsPlist $PWD/MyIosApp/Entitlements-Release.plist -exportPath $PWD/build
altool="$(dirname "$(xcode-select -p)")/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool"
ipa="$PWD/build/MyIosApp.ipa"
echo "Validating app..."
time "$altool" --validate-app --type ios --file "$ipa" --username "$ITC_USER" --password "$ITC_PASSWORD"
echo "Uploading app to iTC..."
cd ../..
#time "$altool" --upload-app --type ios --file "$ipa" --username "$ITC_USER" --password "$ITC_PASSWORD"

Gitlab Continuous Delivery options

I'm iOS developer and
I've been playing with Gitlab lately trying to figure out if it's better/more convenient than redmine+jenkins+HockeyApp. Gitlab seems to be quite cool except for I cannot figure out how to upload my ad-hoc iOS build to HockeyApp (or TestFlight). Is it even possible?
Thanks
Yep, this is definitely possible. I'd strongly recommend using the fastlane Ruby gem.
They even have docs for using it with GitLab CI. You can use pilot specifically to upload the build to TestFlight.
Hopefully that helps :)
I ended up with the following configuration:
add deploy.sh file:
#!/bin/bash
echo "deploy to hockeyapp"
HOCKEYAPP_APP_NAME="MyApp.iOS.ipa"
HOCKEYAPP_TOKEN="MyTOKEN"
HOCKEYAPP_ID="MYAPPID"
function buildNotes {
# We need an initial bullet point for our list of commit logs
echo -n "* "
# Get the latest app uploads
curl -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN" \
"https://rink.hockeyapp.net/api/2/apps/$HOCKEYAPP_ID/app_versions?page=1" | \
# Put every property on a separate line
sed 's/,/\n/g' | \
# Remove all the quotation marks
sed 's/"//g' | \
# Look at only the notes properties
grep notes | \
# Look at the first one, i.e. the latest app upload
head -n 1 | \
# Find the commit information at the bottom of the notes
sed -n 's/.*(commit:\([^)]*\)).*/\1/p' | \
# Let's find all the logs since that commit
xargs -I '{}' git log {}..HEAD --pretty=format:'%h %s' --no-merges | \
# Add a star to each newline to make the list
sed ':a;N;$!ba;s/\n/\n* /g'
# The end of the revision log must have the latest commit
# This is so later we can do the above again
echo
echo -n "* (commit:"
git rev-parse HEAD | xargs echo -n
echo -n ')'
}
function deployAppFlavor () {
echo "executeCurlCommand"
curl -F "status=2" \
-F "notify=1" \
-F "notes=<release_notes" \
-F "notes_type=0" \
-F "ipa=#src/build/MyApp.iOS.ipa/$1" \
-H "X-HockeyAppToken: $2"\
"https://rink.hockeyapp.net/api/2/apps/$3/app_versions/upload"
}
function deployApp {
buildNotes > release_notes
deployAppFlavor $HOCKEYAPP_APP_NAME $HOCKEYAPP_TOKEN $HOCKEYAPP_ID
}
deployApp
and then update yml file:
build_project:
stage: build
script:
- xcodebuild clean -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -quiet
- xcodebuild build -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -destination 'platform=iOS Simulator,name=iPhone 6s' | xcpretty -s > -quiet
archive_project:
stage: archive
script:
- xcodebuild clean archive -archivePath "build/MyApp.iOS.xcarchive" -workspace "MyApp.iOS.xcworkspace" -scheme MyApp.iOS -quiet
- xcodebuild -exportArchive -archivePath "build/MyApp.IOS.xcarchive" -exportPath "build/MyApp.iOS.ipa" -exportOptionsPlist "export.plist" -quiet
artifacts:
paths:
- src/build/MyApp.iOS.ipa
deploy:
before_script:
- chmod +x ./scripts/deploy.sh
stage: deploy
script:
- ./scripts/deploy.sh

Crontab shellscript xcodebuild is not creating .app or .ipa file

I've got a crontab running a shell script for an automated build of an ios app.
Running the shell script from the command line compiles and builds the .ipa with no issue. But when the crontab runs the shell script, the app gets compiled but does not fully finish with an .app or .ipa file. Why doesn't it run the same way?
CONFIGURATION="Adhoc"
OUTPUT_DIR="$PWD/Build/Products/Adhoc-iphoneos"
HOCKEY_TOKEN="token"
DEVELOPER_NAME="name"
########
#
# Cleanup
#
if [ -f "$OUTPUT_DIR/AppName-App.app.dSYM.zip" ]; then
rm -f "$OUTPUT_DIR/AppName-App.app.dSYM.zip"
fi
########
#
# Build The App
#
xcodebuild \
-workspace "AppName.xcworkspace" \
-scheme "AppName-App" \
-configuration "$CONFIGURATION" \
ONLY_ACTIVE_ARCH=NO clean build
########
#
# Code Sign
#
xcrun \
-sdk iphoneos PackageApplication \
-v "$OUTPUT_DIR/AppName-App.app" \
-o "$OUTPUT_DIR/AppName-App.ipa" \
--sign "$DEVELOPER_NAME"\
--embed AppName/BuildResources/AppName.mobileprovision
########
#
# Zip the dSYM
#
zip -r "$OUTPUT_DIR/AppName-App.app.dSYM.zip" "$OUTPUT_DIR/AppName-App.app.dSYM"
########
#
# Upload to HockeyApp
#
curl \
-F "status=2" \
-F "notify=0" \
-F "notes=automated build" \
-F "notes_type=1" \
-F "ipa=#$OUTPUT_DIR/AppName-App.ipa" \
-F "dsym=#$OUTPUT_DIR/AppName-App.app.dSYM.zip" \
-H "X-HockeyAppToken: $HOCKEY_TOKEN" \
https://rink.hockeyapp.net/api/2/apps/upload
When there are differences between a script executed in a logged in shell and via cron, it's almost always environment. Do you know what the value of $PWD is when run via cron? Looks like the provisioning profile you're embedding is using a relative path and might not be found.
I would try making all the paths absolute so you know exactly what the environment is when run in cron.
Also, you aren't showing the actual error messages. Those would obviously help. If you aren't redirecting to a file, cron will mail them to the owner of the crontab.

How to reference current dir from a terminal command

How do I reference the current dir from a terminal command:
xcrun -sdk iphoneos PackageApplication -v "[current dir]/target/My App.app" -o "[current dir]/target/MyApp.ipa"
[current dir] = how do I get this value?
So basically I don't want to type the whole dir out in the command. I want it to look in the dir where it is currently running
xcrun -sdk iphoneos PackageApplication -v "$PWD/target/My App.app" -o "$PWD/target/MyApp.ipa"

Resources