Building iPhone Code using xcodebuild and running LLVM/Clang Static Analyzer - iphone

I followed the steps in Finding memory leaks with the LLVM/Clang Static Analyzer but I was unable to run static analyzer on my project.
When I try to run xcodebuild on my project (1. Open Terminal, 2. Go to Project Directly, 3. > xcodebuild), I get this error:
=== BUILDING NATIVE TARGET XProject OF PROJECT XProject WITH THE DEFAULT
CONFIGURATION (Release) ===
Checking Dependencies... CodeSign
error: no certificate found in
keychain for code signing identity
'iPhone Developer'
\** BUILD FAILED \**
How can I run this tool on my code? - I'm testing with simulator. Thanks.

I'm the author of the blog post that you reference in your question. If codelogic's comments are not enough to point you in the right direction you can wait until a bit later today and I will update the blog post with some more information about running xcodebuild against iPhone projects.
-- Michael
--
Alright, I've updated the post with a section titled iPhone Usage. Hope this helps!
Finding Memory Leaks With The LLVM/Clang Static Analyzer

I haven't used the tool in question but the issue you're seeing appears to be a bothced xcodebuild command. Ensure that your target is the Simulator and not the device (-target command line argument).

It can be tricky to set the base sdk. I like this approach:
I would have sworn that I had already set the sdk via the more traditional 'Build' tab, but hey... The 'Build' tab approach failed me (who know what I did wrong), but this worked great.
Good luck.
[Edit - I just visited the link posted in the Question - which repeats, but does not emphasize, what I'm claiming here.]

It looks strange but I've switched active Configuration to Debug EVERYWHERE but still got same error (like Release is active). Xcode 3.1.3 version.
I was able to fix problem just after removing Release configuration at all from active target.

Related

dyld: Library not loaded: #rpath/libswift_stdlib_core.dylib

I get this error after adding a Swift class to an old Xcode project.
dyld: Library not loaded: #rpath/libswift_stdlib_core.dylib
How can I make the project run again?
For me none of the previous solutions worked. We discovered that there is a flag ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES (in earlier versions: "Embedded Content Contains Swift Code") in the Build Settings that needs to be set to YES. It was NO by default!
This error can occur if something went wrong during the conversion of an Objective-C project to start using Swift. The issue is that the Linker build settings never got configured properly, so you'll have to do it by hand. Look for the Runpath Search Paths build setting and set it to:
$(inherited) #executable_path/Frameworks
EDIT: I should also add that there has been recent spate of these errors caused by something else entirely - Apple made a change in Swift itself, starting in perhaps Xcode 6.1 or 6.1.1. The only solution seems to be to quit Xcode, destroy your certificates in Keychain Access, go to the Member Center and delete all certificates and profiles (except the profiles for apps in the Store - you can't delete them), and then start the entire certificate request process from scratch.
I'm not really sure why this question is being downvoted, I had this problem as well when I first tried to use Swift with an existing project. An Xcode restart also fixed this for me.
I searched long on this issue. There are several reasons causes this issue.
If you are facing when you and Swift code/library in an Objectice C project you should try Solution 1-2-3
If you are facing this issue with a new a Swift project Solution 4 will fit you best.
Solution 1:
Restart Xcode, then computer and iPhone
Solution 2:
Go to project build settings and set Always Embed Swift Standard Libraries (previously Embedded Content Contains Swift Code) flag to YES
Solution 3:
Go to project build settings and add #executable_path/Frameworks to Runpath Search Paths option
Solution 4:
If none of above works, this should. Apple seems to be ninja patched certificates as mentioned in AirSign's post
At InHouse certificates
Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, O=Company Name, C=FR
they added a new field named OU
Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, OU=269J2W3P2L, O=Company Name, C=FR
so you should just recreate certificate and provision
In my case I was trying to import a custom framework and was getting the similar error.
Turns out I had to import the framework in the Embedded Binaries rather than in to the Linked Frameworks and Libraries.
Embedded Binaries are under Projects Settings -> -> General
For developers who have had this issue with a Adhoc/Enterprise distribution builds,
Create the production certificate from dev portal and then regenerate the distribution profile. Download and install both of them on your Mac. Ensure you selected the right profile in your Xcode build settings and rebuild your app.
Source: https://devforums.apple.com/message/1022908#1022908
Solution 5:
In my case, all solutions mentioned in the answer of accfews were very helpful but none has worked. I solved my problem by adding my swift library in the section "Embedded Binaries" in the "General" section of my Project's target. Perhaps is this due to the fact that I have included my swift framework in my workspace? Whatever it compiles now! Get ready Swift, I'm here!
A simple restart of Xcode solved the issue for me.
For me, the issue was due to the fact that my Apple Worldwide Developer Relations Certification Authority was invalid.
Download it from here:
https://developer.apple.com/certificationauthority/AppleWWDRCA.cer
Drag and drop it into Keychain Access, clean the project, and run.
I had an Obj-C project where I started adding swift source files.
The following fixed the issue for me:
Linking: RUNPATH SEARCH PATHS = $(inherited) #executable_path/Frameworks
Swift Compiler - Code Generation: EMBEDDED CONTENT CONTAINS SWIFT = YES
I just created a new project from the templates Xcode 6.3 and compared the project settings with my old original project.
Try to hold Alt, then go to Product -> Clean Build Folder...
Hope it will help someone..
The reasons for this occurring are many. Having just spent a fun weekend finding yet another issue that causes this (the order of code signing), I wanted to create a summary answer that brings all the possible solutions together:
Add Embedded Content Contains Swift Code to project. You need to set this flag if your app contains Swift code.
Clean project. In addition to a Project > Clean you can also delete the DerivedData and Build directories. Look under the Preferences for the location of DerivedData. Build should be in your project folder.
Ensure Runpath Search Paths contains #executable_path/Frameworks.
Ensure that your certificate contains your Apple Team ID in the OU (Organization Unit) field Apple will add this for you, just revoke your existing distribution certificate and create a new one, download, install on KeyChain, regenerate all provisioning profiles, download those and rebuild.
Xcode restart. If everything is basically good, but Xcode hasn't gotten there yet.
That's the easy stuff. If you are doing your own command line build you may be creating your own .ipa files to upload. In that case you need to ensure the following:
Make sure the version of the Swift files in SwiftSupport/iphoneos is the same as the version in Contents/YourApp.app/Frameworks Because Swift is not yet binary compatible between version, you must ensure these versions are the one that you built your app with. You can find these libraries under /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos.
Sign the libraries and frameworks first. You need to codesign the libraries and framework files (under Frameworks in the .app folder) first and then sign the entire .app tree. The .app tree must be signed with an entitlements.plist but not the frameworks.
Hopefully when Swift 3.0 comes out and we no longer need to bundle Swift with our apps this whole issue will go away.
I had this issue using an Ad Hoc (or enterprise) mobileprovision with a production certificate. Switching to a development certificate and mobileprovision solved the issue.
My project is a Swift project with some Objective-C classes.
I had the same problem when signed with old inHouse (enterprise) certificate.
The following steps fixed this for me.
Create and use a new certificate and mobile provision.
(Ref. AIRSIGN’s blog)
Set Runpath Search Paths build setting to: $(inherited) #executable_path/Frameworks.
(Ref. matt’s answer)
Solution 6:
In our case, the Enterprise Distribution Certificate had been revoked. Generating a new certificate and updating the provisioning profile fixed the issue.
(There seems to be many different causes for this error. Hope this helps someone.)
I tried all the answers given above, nothing worked.
Finally worked after updating to Yosemite
I have faced the same issue, setting the right code sign identity solved the problem(Build settings->Code Signing Identity).
As per Apple technical question "All Enterprise and standard iOS developer certificates that are created after iOS 8 was released have the new Team ID field in the proper place to allow Swift language apps to run"
If you add the three frameworks via Embedded Binaries, they will be added to Linked Frameworks and Libraries also. Delete the three entries in Linked Frameworks and Libraries will solve the problem.
Magic methods such as relaunch Xcode and restart the Mac doesn't work on me.
Adding Framework as "Embedded Binary" instead of just "Linked Frameworks and Libraries" - Fixed my issue.
I also set Embedded Content Contains Swift Code flag to YES.
Upgrade to Latest Version of OS X (Yosemite)
After hours of trial & error I came to the resolution of this problem.
- If this applies to your case of course.
I had the same problem until I upgraded my Mac OS X from Mavericks to Yosemite.
- It fixed my problem, hope it fixes yours as well
I tried all the solutions that found on web, including to Apple and new certificates. Without success.
The only way I could run xcode, after 6 months of trying, was creating a new account on my macbook.
Usually this error will disappear if you add this library to the "Copy Files" segment in your Build Phases.
My environment: Cocos2d 2.0, Box2d, Objective C
In addition to doing the other answers above I finally went to the General tab and made WatchKit Optional.
And if all of the above doesn't help you and you really get frustrated... Try the best trick of all: Clean and just to be sure also Clean Build Folder. :) Hope it helps somebody!
None of these solutions seemed to be consistently working for me; after every couple of successful runs, it would fail again. The "Embedded Content Contains Swift Code" flag was always set to YES for me.
Turns out I'd set Xcode to be 6.3-compatible. Changing it back to be 3.2-compatible solved it:
I've had this problem as well, only it wasn't locating libswiftXCTest.dylib.
The solution was to add XCTest.framework to the Tests target, in Build Phases/Link Binary with Library. I was getting this error even when I was trying to build the main target.
This showed up when I added a new Today extension target with Swift language to an old project.
Fixed easily by updating the project to recommended settings. Xcode 6.0.1
I got the same issue using Mavericks, Xcode 6.1.1, testing on an iPhone5 with iOS 8.1.1. I tried all possible solution including new certificates and provisioning profiles, but nothing helped. I did the changes to Embedded Content Contains Swift Code and Runpath Search Paths both on Project level and Target level.
I have now installed Yosemite, and without any further changes, it started to work.
Same issue here, for me it was Crashlytics/Fabric/Beta/Twitter/Whatever-they-call-themselves uploading a binary that was missing the embedded frameworks. If I made an archive and then exported an Enterprise build in the standard way, they worked a charm.
After months and months trying everything here... Definition of insanity... starting Xcode under a new Mac user solved it for me.
I removed ~/Library/Developer/* and reinstalled Xcode- so no clue what else to format to make it work.

RestKit Failed With Error clang failed with exit code 1

I have RestKit 0.9.3 Version and XCode 4.2
Followed the instructions on RestKit for installing on XCode 4.x and i the error mentioned below.
I googled a lot, check many stack answers but none server my problem. I checked the linker flags, they are configured as per the tutorial.
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
Error shown in the image:
if you're building for the iPhone, just make sure you don't have the RestKit.framework added to your target; in the 'Link Binary With Libraries'. HTH
I had this exact same issue. I eventually started a fresh Xcode project, since my project was small, and it worked fine. I suspect this is because I had just converted to Xcode 4.2, and enabled ARC via the tool, I think some things were missed. When I made a fresh Xcode project with 4.2 and put my sources, then ResKit in, it worked just fine.
If your project is small this is a fairly low cost solution. If big, well, hopefully it works!
Yeah, I hate not knowing why, but I also hate wasting time.

Xcode 4 Strip All symbols error when Archiving

I have some static libraries in my Xcode 4 (iOS 4.3 SDK) project. When I archive the project i am getting the following error below when the tool attempts to strip symbols. I have the same settings i used for Xcode 3.2. I have noticed if i change the 'Strip Style' option in build settings from All Symbols to Debugging Symbols then the archive is built successfully.
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip failed with exit code 1
As mentioned above I have not changed this setting from 3.2 so am wondering how to fix this issue?
Thanks
I have met the question like this. I used three20 library in my project, when I archived it. "Strip Symbols Error" about the three20 libraries was produced.
I found the three20 library's "iOS Deployment Target" was "iOS 3.0", but xcode 4.6.3 has no iOS 3.0 sdk. I think it's a problem.
When I changed all three20 libraries' "iOS Deployment Target" to "iOS 5.1", these problems solved.
The fixed place is "Target"->"Build Settings"(All)->"Deployment"->"iOS Deployment".
Please try the following steps. It may be robust for you.
open Terminal window.(find in spotlight
type same code:
sudo /Developer/Library/uninstall-devtools --mode=all
hit enter,it will be ask for ur admin username/pass then press enter.
it will clean your previous directory.
after clean up,it will ask for something,type exit and close terminal.
Now, try installing your Xcode, if you get notification about iTunes (optional)
open activity indicator
find itunes helper process,select it,end process.
After installing new Xcode, restart mac and check.
Thanks
Have you tried to set to NO the build for active architecture only? Are you using in adhoc for your archive? Please try that to see what happens.

Xcode warning: application executable contains unsupported architecture(s):arm, arm (-19031)

I've been receiving this warning since I loaded my project in last Xcode 4 preview. There was no warning before that but now I can't get rid of it even in Xcode 3.2. I've been googling but nobody seems to have the same error.
My project and target settings are correct (IMHO): Architectures: Standard (armv6 armv7), Base SDK: Latest iOS (currently set to iOS 4.2), Build Active Architecture Only: FALSE, Valid Architectures: armv6 armv7.
I compared every project setting with other projects and and found no differences. I even have recreated the project starting from scratch and copying classes, resources and frameworks with the same result.
I must say that the warning is not shown when I set Debug configuration.
I hope someone can help me because I don't know what to do. Thanks in advice.
I kept getting this error and it was driving me crazy. Then I realized I was building the project for Simulator instead of Device. Once I made the change, I was able to upload the app without a problem.
Several things spring to mind. Firstly that there is some file lurking around in the build directory. But I presume you have deleted the build directory. Secondly, that there is something lurking in your library directories. I think xcode puts some tempt files down in them now. Thirdly that something has gone funny is the core xcode setup.
So here's what I would try (the emphasis here is "try" - I don't know if any of this will work :-)
Make sure you have deleted the build directory.
Do a full un-installation of code. Clear out any developer directories and then re-install.
SOLVED!. Not a good solution though.
After a thousand tests I uninstalled Xcode 3.2.5 and installed 3.2.4. Everything went ok since then. Now I'm afraid of upgrade to last version again. :/

Building and code signing an iPhone Application from the command line

I want to make my iPhone Apps in Emacs now, so without using Xcode at all.
How can I build and codesign my app from the command line (even through SSH)? I can't use xcodebuild as there is no Xcode project. Are there any tutorials which cover this? I want to compile them with GCC, and as soon as Developer Tools 4.0 come out, I want to compile them with LLVM.
Can anyone help me? Thanks.
Is it also possible to debug it on the device without Xcode?
You could start with running a build through Xcode and then having a look at the build log. It contains all the commands and respective parameters used to build your project.
Then is should "just" be a matter of creating a make file using the same commands.