iOS Carthage "project has no shared schemes" even with manual xcodebuild - ios

What does this error mean exactly?
If a project doesn't have shared schemes is it possible to create them somehow with xcodebuild -list -project Whatever.xcodeproj?
There seems to be little support for react-native using carthage. I am able to add react-native in my Cartfile and after running carthage update as see react-native in Checkouts. But I also see the error "project has no shared schemes".
So, I manually ran xcodebuild -list -project Carthage/Checkouts/react-native/React/React.xcodeproj - with the idea to do that for all Libraries in react-native, however I'm still unable to do something like #import "React/RCTRootView.h" or import React.
What am I missing?

Try going into Xcode > Products > Scheme > Manage Scheme and making sure your project's scheme is shared.

Related

Linking third party frameworks to my own framework, distributed using Carthage

We have several different proprietary API provided to us as Frameworks that offer similar functionality. The API is of course not identical, so we want to build a wrapper facade Framework around these, so our apps do not need to care which of the API they are using.
As a start, I have created a framework that uses one of these APIs and has unit tests that verifies that it works as expected. We have added the third party framework binary as a part of the project, and the Framework search path is like this:
$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS
$(PROJECT_DIR)
All non-recursive. The Cartage path is here because we use Quick and Nimble for our unit tests. I have the framework in question stored at the project root.
We want to distribute our framework using Carthage, and later also as a Cocoapod.
The problem is that when I try to build our framework by the command: carthage build --no-skip-current --platform iOS, I get the error:
*** Building scheme "Nimble-iOS" in Nimble.xcodeproj
*** Building scheme "Quick-iOS" in Quick.xcworkspace
*** Building scheme "XXX" in XXX.xcodeproj
Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/andre/Development/yyy/xxx/XXX.xcodeproj -scheme XXX -configuration Release -sdk iphonesimulator -destination platform=iOS\ Simulator,id=AE9E3D9D-BE2C-4AE1-AB37-C6BE8948067B -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/andre/Development/yyy/XXX)
And the log contains this:
iphonesimulator/XXX.build/Objects-normal/i386/XXXLockService.o
/Users/andre/Development/yyy/XXX/XXX/LockServiceFactory.swift:7:71: error: 'PinServiceAccessImpl' is unavailable: cannot find Swift declaration for this class
case .xxx: return XXXLockService(lockService: PinServiceAccessImpl.getInstance())
^~~~~~~~~~~~~~~~~~~~
PinServiceAccess.PinServiceAccessImpl:2:12: note: 'PinServiceAccessImpl' has been explicitly marked unavailable here
open class PinServiceAccessImpl : NSObject {
When using a framework from an app, the documentation states that we should add the framework's as an embedded binary, but this option is not available when the project is a framework.
What puzzles me is that the unit tests seems to find the PinServiceAccessImpl.getInstance()!
I guess there are some details about linking that I don't know about that makes the build fails. Does anyone have an idea of what we are missing out?
The problem got solved when updating the deployment target to 11.0.

xcodebuild linker failing when custom output directory provided

I have a problem using xcodebuild to build the iOS app to custom directory.
Everything works well if I am building using command:
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyAppScheme -sdk iphoneos -configuration Release ONLY_ACTIVE_ARCH=NO
...but I would like the .app and .dSYM files to be saved in a specific directory (./build for example). So, I tried adding:
CONFIGURATION_BUILD_DIR=./build
or
OBJROOT=./build SYMROOT=./build
as a xcodebuild parameters. Then I've got this error (output comes from xctool as it's more readable, but the same error occurs when using xcodebuild):
✗ Link MyApp
(...)
ld: library not found for -lPods-MyApp-SomePodName
clang: error: linker command failed with exit code 1 (use -v to see invocation)
As I am using Cocoapods, my workspace contains app's project and "Pods" project. I tried using xcodebuild on several other projects that uses Cocoapods and I am always getting this error (SomePodName differs depending on project's dependencies) when trying to provide custom output directory. Please note, that it works without an issue when CONFIGURATION_BUILD_DIR, OBJROOT and SYMROOT parameters are skipped.
I wonder if anything changed recently, because I am pretty sure that I was able to build to custom directory using xcodebuild in the past. Currently, Travis-CI is still able to do it without an issue, but I have no luck when trying on my local machines.
Perhaps providing CONFIGURATION_BUILD_DIR, OBJROOT or SYMROOT is not the perfect way for specifying custom output directory. I am not sure if the problem is connected directly to Cocoapods, but the errors are always connected with some pod library.
Any hints will be appreciated.
My environment:
OS X 10.10.3
Xcode 6.3
xctool 0.2.3
cocoapods 0.36.3
Update: Problem solved
It looks like xcodebuild requires absolute path for CONFIGURATION_BUILD_DIR, OBJROOT and SYMROOT parameters.
Providing absolute path solved the problem:
CONFIGURATION_BUILD_DIR=/Users/me/Dev/MyApp/build

How do I use SwiftyJSON in my iOS App?

I recently added SwiftyJSON into my xCode project using Carthage.
Cartfile
$ cat Cartfile
github "SwiftyJSON/SwiftyJSON" >= 2.1.2
I ran this command to install SwiftyJSON
$ carthage update
I added the built Framework to my xCode project
I imported the Framework at the top of my project
But I still get this error:
Use of unresolved identifier 'JSON'
Seriously, what am I doing wrong? I'm new to iOS development.
UPDATE: I tried removing the Frameworks and re-dragging the frameworks to the Linked Frameworks and Libraries and Adding the "Run Script" section to "Build Phases" as the instructions in Carthage asked.
I'm convinced that something went awry during the Carthage Update process because I received this error on my initial attempt:
$ carthage update
*** Fetching SwiftyJSON
*** Fetching Alamofire
*** Checking out SwiftyJSON at "2.1.3"
*** Checking out Alamofire at "1.1.4"
*** xcodebuild output can be found in /var/folders/0x/swzt630n3_575tglljpwhn4h0000gn/T/carthage-xcodebuild.Pc6rLg.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "SwiftyJSON" in SwiftyJSON.xcworkspace
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
After looking up the problem, I was told that you could run
carthage update --configuration Debug
Which installed it fine, but something is still amiss...
It seems like you missed a step during the addition of SwiftyJSON and Alamofire frameworks from Carthage. Check out these steps from the Carthage readme page :
Steps :
Create a Cartfile that lists the frameworks you’d like to use in your project.
Run carthage update. This will fetch dependencies into a Carthage/Checkouts folder, then build each one.
On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
$(SRCROOT)/Carthage/Build/iOS/SwiftyJSON.framework
Looks like you missed step 4. I tried these steps myself in a demo Swift project and they are working great. Try these steps out, and if you still have problems, leave a comment. Thanks!
I switched over to Cocoapods and it just worked. Again, I'm a total noob when it comes to iOS development. When looking for a dependency manger I looked at Cocoapods and Carthage for what they had to offer. I was intrigued by Carthage's claim of keeping things simple:
"Carthage because we wanted the simplest tool possible—a dependency manager that gets the job done without taking over the responsibility of Xcode"
While I always will choose the simpler tool when given a choice, I think I don't know enough of the iOS ecosystem (read: Xcode) to use Carthage.
TL,DR: Can't use it inside of Emulator, Use iPhone.
I also followed your way, and I found out that --configuration debug will code-sign "iOS Developer" identity as SwiftyJSON's project property.
AFAIK, Code-signed "iOS Developer" identity wasn't run with Emulator.
My issue was resolved when I run it at my iPhone 6.
I do not know why you can not add this resource with help of Carthage but if you need use SwiftyJSON you only need:
Enter this URL: SwiftyJSON
Clic the button "Clone or download" and then in "Download ZIP" like the next image shows:
Clic the button "Clone or download" and then in "Download ZIP" IMG
You will get a ZIP file with name "SwiftyJSON-master"
Extract the files
Enter the path:
SwiftyJSON-master/Source/
You will see a file with name:
SwiftyJSON.swift
Copy that file into the files of your project.
Add that file into your project directory.
That file will be like other class into your project that you may use.

Why when generating .app file, xcode needs to be open?

I'm writing a script to build and generate an .app file from an specific target and scheme (to work with simulator). I was using something like:
DEVELOPER_DIR=$xcode_app_path/Contents/Developer xcodebuild -sdk iphonesimulator -scheme "${SCHEME}" -target "${TARGET}" ONLY_ACTIVE_ARCH=NO CONFIGURATION_BUILD_DIR="${build_folder}" clean build
The problem is, that I need to open XCode for the code above to work, otherwise will show me a message telling me that:
xcodebuild: error: The project 'Project-name' does not contain a scheme named "${SCHEME}"
I still yet, don't understand what is XCode doing in background. But if I open the IDE and run the script, works. If I open and later close it, and run the script works. It's not working if the project hasn't been opened first with XCode ¬¬
Any suggestion would be appreaciated
If someone is facing the same experience, this is what I found out. And works.
Well, apparently when you create a new scheme through command line, by default is not "shared". So when you start to link to the folder
xcshareddata --> xcschemes
(trying to build with command line, for example) there's nothing to link with. Xcode do this automaticaly under the hood when you open your project...
The guys from CocoaPods were facing the same issue, so they created a Ruby gem that shares the scheme and place the file in his xcscheme folder:
This is the repo: https://github.com/CocoaPods/Xcodeproj
Also, thanks to this post and this post I found out how to use xcodeproj gem, and change the shared option with a script that I put downhere:
require 'xcodeproj'
xcproj = Xcodeproj::Project.open("MyProject.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save

Target Properties changes by xcodebuild command

How can i manipulate my iOS Target Properties by xcodebuild command tool ?
In example, i have one project with one target and with Facebook SDK Key in Target Properties in Info tab
FacebookAppID: 01234567891234
And with console command xcodebuild i'm compiling two Apps with Developer and Production provisions with two console commands:
For Developer:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneDeveloper} PROVISIONING_PROFILE="Dev.mobileprovision"
For Distribution:
xcodebuild -project Projectname.xcodeproj clean install OBJROOT=ObjRoot ... CODE_SIGN_IDENTITY={iPhoneProduction} PROVISIONING_PROFILE="Prod.mobileprovision"
And i need use in Developer one FacebookAppID, and in Production a other FacebookAppID, and how i can change my command lines for realize this?
Thanks
Arguments to xcodebuild are best used for values that change every time they're invoked, like a destination directory that includes a build number.
For data as foundational as a Facebook app ID, I'd recommend using your build configurations, e.g. "Debug" and "Release". Create a user-defined build setting (in Xcode 5.0.2, Editor -> Add Build Setting -> Add User-Defined Setting) named something like "FACEBOOK_ID", and in your Info.plist, set your desired key's value to ${FACEBOOK_ID}. In your target's build settings, define FACEBOOK_ID differently for your Debug and Release configurations. Your code then now has to pull the current value out of Info.plist at runtime.
If you really want to override build settings as arguments to xcodebuild, you can do so, just by adding "FACEBOOK_ID=12341234" to the end of the command, but this only works if you've done the work I just described to make FACEBOOK_ID into a configuration-specific build setting. I can't think of any sound reasons to keep this kind of app data outside of a build configuration.
If build configurations are new to you, I'd suggest starting with WWDC 2012 session 408, "Working with Schemes and Projects in Xcode".

Resources