(iphone) build xcode4 project from command line - iphone

I've used to build my project with
xcodebuild -proj MyProject.xcodeproj -target MyTarget - configuration Debug -sdk iphonesimulator4.3
this works(it builds fine) but when I hit run in xcode, it recompiles.
(with xcode3, there was no need to rebuild once I build using command line)
I suspect xcode build use workspace/scheme rather than project/target.
How do I find out the workspace name that my current xcode project is using?
Thank you
edit
Chetan's links gave me directions what to look for.
xcode4 stores build output in ~/Library/...
whereas xcodebuild -project .. saves build output in project's build directory.
(if you want the workspace capability, you can't use the build directory for build output)
I created a workspace containing my project and ran
xcodebuild -workspace myWorkSpace -scheme myScheme
this saves build output in ~/Library/...../Debug-iphoneos
whereas xcode4 run button from the same workspace and same scheme saves output in
~/Library/..../Debug-iphonesimulator
any guess on why xcodebuild command uses Debug-iphoneos? :(
edit2
xcodebuild -workspace myWorkSpace -scheme myScheme -sdk iphonesimulator4.3
specifying sdk solved it

I know it isn't strictly the answer to your question, but you can configure the output directory of your build using the CONFIGURATION_BUILD_DIR environment variable.
Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40003931-CH1-SW1

Related

Error While creating Custom Framework and xcframework

I am creating a Framework where i am adding multiple Third Party Libraries manually. and creating a Fat framework SomeFrameworkName.framework using the script below
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
After Archiving i am able to get the framework file but when i try to add that framework into the demo project it gives me multiple errors as follows:
dyld: Library not loaded: #rpath/TestIOS.framework/TestIOS
Referenced from: /private/var/containers/Bundle/Application/E76B5EA8-2E7C-44A4-BDCC-A8AB0B37E500/TestAshishDemo.app/TestDemo
Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
or else any library names comes in the picture.
and whenever i try to create the xcframework file i get the following error
Failed to build module from its module interface; it may have been damaged or it may have triggered a bug in the Swift compiler when it was produced
i am on a crucial stage to solve this error. Anyone if facing the same issue or faced the same along the way they created framework Please Help me out
XCode Version - 12.5.1
In your target project, did you try to embed the Framework ?
(Old XCode screenshot of mine here)

`swift build` on Terminal throw `error: root manifest not found`

I wanna run my swift programing on Terminal, so I cd the root folder of my project, and run $ swift build, but there is a error occurred.
$ error: root manifest not found
Any help?
In case anyone else stumble upon the same problem, the solution for me was to cd to the Sources folder of my scripts, not the root folder.
I had this error happen to me when I was building a CLI tool on Xcode. First off, when Xcode talks about root manifest, it means package.swift. You don't have one in your directory or parent directories. I discovered 2 options:
Instead of swift build, use Xcode's UI or xcodebuild CLI and get the build files in finder/ terminal
For debug, build the build normally, and you can right click the file generated in the Project Navigator like below:
For release build, run Archive in Xcode instead and you can get the build files: Project Name 25-03-2021, 11.30.xcarchive/Products/usr/local/bin/executable in my case the executable is called Image Labeling
or, add a package.swift
Instead of creating the project through Xcode (CLI tool template) use the swift cli tool instead: swift package init --type executable . In this case, swift build works everywhere in the project, not just in Sources because package.swift was added to the root of the project.
When you call the
-Swift build
command you must use it from Swift Package Manager and you should have 2 folders in the directory:
Source
Test
you should use the following command for project:
- name: Build
run: |
xcodebuild clean test -project "yourproject.xcproject" -scheme "yourproject" -destination "platform=iOS Simulator,name=iPhone 12 Pro,OS=latest" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO
and you should use the following commands for workspace:
- name: Build
run: |
xcodebuild clean build -workspace "yourproject.xcworkspace" -scheme "yourtarget" -destination "platform=iOS Simulator,name=iPhone 12 Pro,OS=latest" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO
- name: Test
run: |
xcodebuild clean test -workspace "yourproject.xcworkspace" -scheme "yourtargetTests" -destination "platform=iOS Simulator,name=iPhone 12 Pro,OS=latest" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO

Auto switch Xcode Config when testing simulator and devices

I managed to use Xcconfig to build my app, but as in the config itself, I need to specify such as...
ARCHS = $(ARCHS_STANDARD_32_BIT)
SDKROOT = iphoneos
So I have two files, such as Debug-Simulator.xcconfig and Debug-Device.xcconfig.
But in the XCode, I can only attach one Debug and one Release XCodeConfig, so how to auto change the configuration automatically without I change the Debug configuration manually?
You can conditionalize lines of your .xcconfig file based on the SDK name. For instance...
ARCHS[sdk=iphoneos*] = armv7
ARCHS[sdk=iphonesimulator*] = $(ARCHS_STANDARD_32_BIT)
I think that's what you're looking for here, right? I'm not sure the full extent of these predicates' syntax, but the above works for me when trying to change build settings beteen Simulator and Device.
You can even use this to conditionalize for multiple versions of SDK, like they do here: Base.xcconfig
Are you using Command-line?
xcodebuild -configuration Debug ...
xcodebuild -configuration Release ..
You can refer to the usage of xcodebuild.
Options:
-usage print full usage
-verbose provide additional status output
-project NAME build the project NAME
-target NAME build the target NAME
-alltargets build all targets
-workspace NAME build the workspace NAME
-scheme NAME build the scheme NAME
-configuration NAME use the build configuration NAME for building each target
-xcconfig PATH apply the build settings defined in the file at PATH as overrides
-arch ARCH build each target for the architecture ARCH; this will override architectures defined in the project
-sdk SDK use SDK as the name or path of the base SDK when building the project
-parallelizeTargets build independent targets in parallel
-jobs NUMBER specify the maximum number of concurrent build operations
-showsdks display a compact list of the installed SDKs
-list lists the targets and configurations in a project, or the schemes in a workspace
-find BINARY display the full path to BINARY in the provided SDK
-version display the version of Xcode; with -sdk will display info about one or all installed SDKs

iphone sdk 4.3 running unit test from command line

i like to run test cases from the command line but there is a little problem… maybe someone can help me…
i' ve created a simple HelloWorld Project with XCode4! The build works fine.
xcodebuild -project HelloWorld.xcodeproj -target HelloWorld -sdk iphonesimulator4.3 -configuration "Debug"
But the test doesn't work (i use the default unit test which xcode4 creates)
xcodebuild -project HelloWorld.xcodeproj -target HelloWorldTests -sdk iphonesimulator4.3 -configuration "Debug"
Here are some interesting outputs:
=== BUILD NATIVE TARGET HelloWorld OF PROJECT HelloWorld WITH THE
DEFAULT CONFIGURATION (Release) ===
Check dependencies
And
/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/Tools/RunPlatformUnitTests:95:
warning: Skipping tests; the
iPhoneSimulator platform does not
currently support application-hosted
tests (TEST_HOST set).
I guess the last output is the problem but i haven't any idea to fix it :-(
It sounds as though you may have unit tests and application tests mixed up. Referring to the two following sources (especially the non-apple one) will help you out a lot:
Apple's Documentation
CocoaWithLove Article

Automating Xcode development

Can everything which is done through Xcode GUI be done through command line, like changing app name, changing provisional profile, distribution profile? If yes then how. May be it can be done through xcodebuild , but till now i am only able to compile through xcodebuild.
Yes. Building can be done through xcodebuild:
$ xcodebuild -help
Usage: xcodebuild [-project <projectname>] [-activetarget] [-alltargets] [-target <targetname>]... [-parallelizeTargets] [-activeconfiguration] [-configuration <configurationname>] [-sdk <sdkfullpath>|<sdkname>] [-xcconfig <filepath>] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild [-version [-sdk [<sdkfullpath>|<sdkname>] [<item>] ]
xcodebuild [-showsdks]
xcodebuild [-find <binary> -sdk <sdkfullpath>|<sdkname>]
xcodebuild [-list]
…but I see you already know that. The application name can be changed by simply editing the Info.plist file. And I think you can change the profiles by hacking the *.pbxproj file (it’s a regular text file). You can save a copy of the project file, change a profile through the IDE and then diff the new version and the saved copy to see the changes:
$ find . -name '*.pbxproj'
./Source/Foo.xcodeproj/project.pbxproj
$ cp Source/Foo.xcodeproj/project.pbxproj ~/Desktop
# …now changing the profile through IDE…
$ diff Source/Foo.xcodeproj/project.pbxproj ~/Desktop/project.pbxproj
517d516
< "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "…";
534d532
< "PROVISIONING_PROFILE[sdk=iphoneos*]" = "…";
But it depends on what you are trying to do. You could switch the profiles much easier by setting different profiles for different build modes (Debug/Distribution/Whatever).