69

I just updated my iPhone 4S software to iOS 7 Beta 2 while I was in the middle of putting the final touches on a new app (Phonegap).. not a good idea!

After it was done Xcode didn't detect my iPhone so I installed Xcode 5 beta. After tinkering around with it I finally got it to detect my phone. The only problem now is there is an error with the architecture used.

Here are the errors being produced:

ld: warning: ignoring file /Users/-----------/Library/Developer/Xcode/DerivedData/testtest-bmnbmujiosugcmgeiceofgcfmsec/Build/Products/Debug-iphoneos/libCordova.a, file was built for archive which is not the architecture being linked (armv7s): /Users/--------/Library/Developer/Xcode/DerivedData/testtest-bmnbmujiosugcmgeiceofgcfmsec/Build/Products/Debug-iphoneos/libCordova.a
Undefined symbols for architecture armv7s:
  "_OBJC_METACLASS_$_CDVCommandDelegateImpl", referenced from:
      _OBJC_METACLASS_$_MainCommandDelegate in MainViewController.o
  "_CDVLocalNotification", referenced from:
      -[AppDelegate application:didReceiveLocalNotification:] in AppDelegate.o
  "_OBJC_CLASS_$_CDVCommandDelegateImpl", referenced from:
      _OBJC_CLASS_$_MainCommandDelegate in MainViewController.o
  "_OBJC_CLASS_$_CDVCommandQueue", referenced from:
      _OBJC_CLASS_$_MainCommandQueue in MainViewController.o
  "_OBJC_METACLASS_$_CDVViewController", referenced from:
      _OBJC_METACLASS_$_MainViewController in MainViewController.o
  "_OBJC_METACLASS_$_CDVCommandQueue", referenced from:
      _OBJC_METACLASS_$_MainCommandQueue in MainViewController.o
  "_CDVPluginHandleOpenURLNotification", referenced from:
      -[AppDelegate application:handleOpenURL:] in AppDelegate.o
  "_OBJC_CLASS_$_CDVViewController", referenced from:
      _OBJC_CLASS_$_MainViewController in MainViewController.o
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas on what the architecture should be changed to in order to get it to work on my phone? (it's working fine on the emulator)

MattDavey
  • 8,897
  • 3
  • 31
  • 54
barney
  • 891
  • 1
  • 8
  • 12

7 Answers7

105

Short answer:

  • Remove Build Active Architecture Only (build setting parameter key is 'ONLY_ACTIVE_ARCH') from all of your static libraries' project build settings or overwrite it with 'NO' like in the screenshot below: Overwrite 'Build Active Architecture Only' to 'NO' or delete it's entry completely to fallback to iOS Default

Detailed answer:

The problem is that your static library 'libCordova.a' which you're linking in your main app is only compiled for one architecture (armv7, but not armv7s).

You've probably let Xcode perform all the recommended changes for your static libraries project without reading what these changes actually are. Speaking for myself, I've never bothered to take a closer look at that info dialog (screenshot below), when I switched over to a new version of Xcode -- until now. enter image description here

The problem is that performing these changes activates for debug builds a new feature called Build Active Architecture Only (build setting parameter key is 'ONLY_ACTIVE_ARCH'). In principle, this is a very cool enhancement of Xcode, because setting this to YES leads to faster building times, as Xcode only compiles the architecture of the connected device you've currently selected at the top when you hit the run button.

However, when blindly accepting this new parameter in a static library, you may run into this bug. The bug occurs when you've built the debug version of a static library while having connected an armv7 device, and then, when you're debugging your main application, you've connected an armv7s device (or vice versa). Subsequently you'll get the error above (or a similar one).

So my recommendation is to completely remove the value at project level for Build Active Architecture Only from all of your static libraries' project build settings. Because if you take a look at the iOS default, it is NO. Of course you can also overwrite the setting to 'NO' to be sure the setting is correct even if in the future the default value will change (cf. 1st screenshot).

Tafkadasoh
  • 4,667
  • 4
  • 27
  • 31
  • Didn't work for me. I'm on simulator. Anything else is missing? – Van Du Tran Sep 13 '13 at 14:40
  • @Tafkadasoh do you happen to know how to disable this warning in Xcode 5 (Without disabling any other source code related warnings) ? – user1264176 Sep 23 '13 at 15:56
  • A clarification that helped me use this info: Note that you need to make the suggested change in your CordovaLib.xcodeproj target (I'm using PhoneGap 2.9) and not just your PhoneGap app target. If you don't change it in the CordovaLib target, even a clean/build won't force the libCordova.a to be built with the right architectures. – JA_251 Sep 26 '13 at 15:19
  • I found this answer after figuring out essentially the same thing (thank you for validating what I thought was the correct solution!). Alas, it isn't making a difference, and I'm still getting lots of errors. (This all went south for me after trying to add arm64 to the mix, then changing it back.) – Joe D'Andrea Sep 27 '13 at 18:53
  • I ran into this issue using Cordova 3.0 and XCode 5. This fix worked beautifully! – David Myers Oct 01 '13 at 05:04
  • I believe you can just clean your project, and that will force a rebuild of the library and will compile it for the device currently connected. There shouldn't be any need to change the Build Active Architecture flag, doing so will just make unnecessarily long build times when debugging. To clean your project in xcode, go to Product->Clean. (Or command + shift + K) – njtman Oct 02 '13 at 19:12
  • 1
    @rkaartikeyan Just select the corresponding row in your project settings (cf. 1st screenshot) and hit the backspace key. – Tafkadasoh Oct 25 '13 at 14:34
  • Thank you .It stopped working all of a sudden It took me hours to figure it out. This is helpful – Gowthami Gattineni Jan 30 '14 at 19:45
  • This solved my issue as well. It was in the CordovaLib where I had to set it to No. – islanddave Oct 14 '14 at 20:13
75

If your project was built using Cordova 2.x and Xcode 4.x, and you are receiving the error mentioned by the OP, this solution worked for me. (I was experiencing the error with Cordova 2.5 and Xcode 5).

https://issues.apache.org/jira/browse/CB-3768

Go to your Cordova Project

Root Folder -> CordovaLib -> Right Click CordovaLib.xcodeproj -> Show Package Contents -> Open project.pbxproj

Replace all occurrences of (I had 4)

buildSettings = {
    ALWAYS_SEARCH_USER_PATHS = NO;//in 2 out of 4 occurrences
    "ARCHS[sdk=iphoneos*]" = armv7;
    "ARCHS[sdk=iphoneos6.*]" = (
        armv7,
        armv7s,
    );
        /* other settings here */
};

With this

buildSettings = {
    ALWAYS_SEARCH_USER_PATHS = NO;//in 2 out of 4 occurrences
    "ARCHS[sdk=iphoneos*]" = armv7;
    "ARCHS[sdk=iphoneos7.*]" = (
        armv7,
        armv7s,
    );
    "ARCHS[sdk=iphoneos6.*]" = (
        armv7,
        armv7s,
    );
    /* other settings here */
};

Now your project will build fine!

Christopher Rogers
  • 6,759
  • 1
  • 22
  • 13
njtman
  • 2,160
  • 1
  • 19
  • 32
  • Worked perfectly for me with Cordova 2.7 and XCode 5. – Dave Reynolds Sep 28 '13 at 19:20
  • 4
    The solution by Tafkadasoh did not work for me. This works perfectly! Thanks. – JP Richardson Sep 29 '13 at 04:37
  • Worked great for me, with a Cordova 2.6 project. I'm surprised the "iphoneos7.*" entry cannot be made through the xcode user-interface... – plang Oct 03 '13 at 06:37
  • This seems not the case anymore with Cordova 3.1 – Ghigo Oct 10 '13 at 00:07
  • @Ghigo As my answer states, this solution is only for Cordova 2.x. These settings should already more or less exist in Cordova 3.x, because it supported iOS7 from the beginning. – njtman Oct 10 '13 at 15:26
  • Worked perfect for me! Thanks – Tomjr260 Oct 14 '13 at 18:10
  • I went into the build settings for the Cordova lib and changed the Architectures drop-down to use "Standard Architectures". I believe this is equivalent - basically adding armv7s compilation to the list. – jocull Oct 20 '13 at 19:15
  • can you elaborate on this? I tried to following your description in xcode, but I got lost. @jocull – njtman Nov 11 '13 at 16:35
  • When you click on the project there is a section called "Build Settings" - you should be able to find it in there. – jocull Nov 11 '13 at 16:56
  • Worked for me with Cordova 3.4.0 and XCode 5.1, though I didn't have any ARCHS settings in my 2 configurations before I added the ones you recommended. Thanks so much! – Brad Griffith Mar 19 '14 at 16:03
13

I have removed armv7s from valid architectures section and it worked for me.

Build Settings --> Architectures --> Valid Architectures

Xcode Build Settings

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
  • 1
    I was updating to Xcode 5.1 (which come out at the same time as iOS 7.1). I ended removing all Valid Architectures *except* armv7 armv7s. Then, my phonegap app compiles and builds. – Thomas - BeeDesk Mar 13 '14 at 08:27
  • @Thomas-BeeDesk :But do you have idea what does this happen ? in a way we drop support to build64 bit binary and only 32 binary will be generated now ? any thoughts...and if the library do not support 64 bit , why there was no error when i run it on xcode 5.0 and ios 7.0 on a 64 bit device? – Ankit Mar 13 '14 at 10:37
  • @ankit, I believe all cpu in the iPhone is backward compatible (so far). The code in `libCordova.a` will run with only 32-bit instructions. The bulks of our app should be JavaScript executing inside a native UIWebView anyway, I don't think it really matter or would have significant perf impact. – Thomas - BeeDesk Mar 14 '14 at 03:24
11

I am using Xcode 5 so iOS SDK 7. The solution which worked for me was simply to remove the arm64 architecture.

Select the project target (NOT CordovaLib.xcodeproj) and in the build settings>Valid Architectures, remove arm64 if it's there in the list. Here is mine after I remove arm64 architecture.

enter image description here

Malloc
  • 15,434
  • 34
  • 105
  • 192
4

Because my lib.a is for only armv7

what i did was

Active Architecture Only = yes

buildSettings = {
                ALWAYS_SEARCH_USER_PATHS = NO;
                "ARCHS[sdk=iphoneos*]" = (
                    armv7s,
                    armv7,
                );
                "ARCHS[sdk=iphoneos6.*]" = (
                    armv7s,
                    armv7,
                );
                "ARCHS[sdk=iphoneos7.*]" = (
                    armv7,
                    armv7s,
                );

it was build and archived fine

hope it helps

  • 1
    I believe you can just clean your project, and that will force a rebuild of the library and will compile it for the device currently connected. There shouldn't be any need to change the Build Active Architecture flag, doing so will just make unnecessarily long build times when debugging. This should eliminate errors when deployed to different device types when debugging. To clean your project in xcode, go to Product->Clean. (Or command + shift + K) – njtman Oct 08 '13 at 13:27
  • dear njtman,yes you are right, just clean project it 's work find for the connected device. But for me, I have to archive the project for not connected device. but whech i archive it ... the problem is still there. So I try this one and it work find for me :). btw, Thx for your tip. – ruzticgirlz Oct 09 '13 at 07:33
  • @hypery2k how do you know your lib.a is only for armv7? – June Wang Mar 11 '19 at 02:52
2

njtman had a correct answer. I don't have the rep to comment so I am adding more details.

You need a iOS 7 SDK to use the standard architectures (armv7,armv7s).

My project was defaulting to (armv7), not including armv7s.

To fix this, Open CordovaLib.xcodeproj, Under Build Settings (one of the menus in the top row, centered alignment) Under architectures, Architectures, Debug and Release, ADD iOS 7.0 using Standard architectures.

njfrost
  • 95
  • 1
  • 8
0

In Build Settings...

Strip Debug Symbols During  Copy: 

Debug: No

Release: No
Cam Tullos
  • 2,537
  • 1
  • 21
  • 18