128

Fresh vanilla submodule install of Alamofire, using XCode6 and following directions to a T. Something here just isn't fitting right. The error i'm getting is "Could not build objective-c module "alamofire" on import alamofire. Here is a screen shot of the error i'm getting:

enter image description here And my configuration:

enter image description here

stopshinal
  • 1,891
  • 4
  • 16
  • 24
  • http://stackoverflow.com/questions/26503389/how-to-run-alamofire-library/26504552#26504552 – Saurabh Prajapati Nov 10 '14 at 04:33
  • i think you have to install alamofire as per instruction given here https://github.com/Alamofire/Alamofire – Saurabh Prajapati Nov 10 '14 at 04:36
  • did you get it to work? it worked for me and after another "Build and run" it stopped and i got the same error message... :( – Georg Dec 15 '14 at 19:37
  • 2
    A colleague just had the same error message but the reason turned out to be that he was still using Xcode 6.1 (it's the 6.3 era we're in as I write this). Saying this just for the record, should anyone else struggle with the same thing. – villapossu Jun 02 '15 at 12:29

12 Answers12

118

When this happens, just build the frameworks separately first. In your case:

  • Change the scheme to Alamofire
  • Build (⌘B)
  • Change back to your scheme
  • Run
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
  • 4
    Great answer; I was oblivious to changing the build scheme to fix these sorts of errors! – tehprofessor May 10 '15 at 02:26
  • 7
    If you have to build the scheme separately, it probably means you do not have the framework set as a target dependency in the build settings of your application correctly. Do this and you should not have to build it manually. – Charles A. Oct 12 '15 at 21:26
  • I voted this up, since it works in Xcode. Unfortunately it won't work if building from the command line or if building for Release. – Eneko Alonso Mar 31 '16 at 23:06
  • This fixed an issue I was having with GoogleApiClient/Drive. Build would succeed, but as soon as any changes were made to the file, Xcode would complain about the import. – Nick Alexander Aug 25 '16 at 02:45
  • 1
    Thanks a lottt sirr, this help me so much – Ridho Octanio Feb 04 '20 at 03:28
57

Go into Developer/Xcode/DerivedData and delete the folder for your framework. (Or just delete DerivedData itself)

If you have a build of you app in a running simulator you'll need to delete the app there.

Then Clean & Build

Sean Howell
  • 876
  • 7
  • 8
  • This worked for me also, but then i encounter multiple command produce, this link will help : https://stackoverflow.com/questions/50718018/xcode-10-error-multiple-commands-produce. – Bhimbim Aug 14 '19 at 04:52
35

This always works for me:

  1. Quit Xcode
  2. Delete ~/Library/Developer/Xcode/DerivedData
  3. Change to your framework’s scheme and build ⌘B
  4. Change to your app’s scheme and build ⌘B
Sam Soffes
  • 14,831
  • 9
  • 76
  • 80
24

Deleting the DerivedData folder and cleaning and building the project solved this issue for me.

Isuru
  • 30,617
  • 60
  • 187
  • 303
15

If you're getting this error trying to import a dynamic framework, make sure the framework is included in the target's Target Dependencies.

Project > "Target" > Build Phases > Target Dependencies

David James
  • 2,430
  • 1
  • 26
  • 35
  • Also, if you are working with another framework developed in the same workspace, make sure to add the Project as a linked library instead of the framework file, otherwise the framework won't be visible as a target dependency. – Dávid Pásztor Jul 18 '19 at 12:13
15

Try the following in this order and one of the steps should work.

  1. Cmd+B - Builds the workspace and should possibly build the target or module we want.

  2. Cmd+K and then Cmd+B - Clean and then Build

  3. Cmd+Shift+Option+K and Cmd+B - Clean Build Folder

  4. Quit Xcode, Delete Derived Data, launch Xcode and Cmd+Shift+Option+K then Cmd+B

This happens to be the cleanest possible way to clean the derived data and other caches from Xcode.

Ky -
  • 30,724
  • 51
  • 192
  • 308
ravisekahrp
  • 461
  • 4
  • 7
  • For those using iCloud sync (For example, having the project in Documents folder so it would be easily sync to multiple Mac's), check for file with name: `XXX 2.swift`. Search and delete all of them, then run `pod install`. – John Pang May 09 '19 at 13:50
11

Build clean worked for me.

  1. Build clean for Alamo
  2. Build clean for HTTPDemo
Nick Mitchell
  • 1,207
  • 13
  • 24
10

Comment out the import and all code using it, build, run, then uncomment. It worked for me...

xytor
  • 406
  • 4
  • 16
2

Any pod failed to build may cause this error as well. (in my case an old pod using obsolete syntax failed to build).

You may try pod update to update your pods to latest version and see how thing goes.

Gang Fang
  • 787
  • 7
  • 14
  • For those using iCloud sync (For example, having the project in Documents folder so it would be easily sync to multiple Mac's), check for file with name: `XXX 2.swift`. Search and delete all of them, then run `pod install`. – John Pang May 09 '19 at 13:51
  • This helped me. I had an outdated pod that still is under development and I just forgot to run pod install. – atereshkov Sep 08 '20 at 12:15
1

I resolved this issue in one of my Objective-C/Swift hybrid projects.

In your Objective-C bridging file, add the following line:

#import <Alamofire/Alamofire.h>

Eddie Lau
  • 668
  • 7
  • 12
1

Crazy fix for this issue - Only working solution for me

Create new scheme and add the framework that is showing error. In this case 'Alamofire'. Run all those schemes.

Once you compile all the schemes your project target will also works fine.

It may seem like a crazy fix but only working solution for me.

Saranjith
  • 11,242
  • 5
  • 69
  • 122
0

If valid architectures of the Alamofire project do not contain the valid architectures of your project, it occurs "Could not build objective-c module .." error.

Add these architectures i386 x86_64 arm64 arm64e armv7 armv7s armv6 armv64 to the Alamofire project's 'Valid Architectures' on the 'Build Settings'.

Build the same target device for both of the projects. For example, at first, build the Alamofire project for iPhone 8(13.2), then build your project for the same simulator.

If the Alamofire project build takes very short that means about 0.5 seconds, it means the Alamofire project occurs error because the architecture of the selected simulator is not on the Valid Architectures.

Yusuf
  • 851
  • 6
  • 14