Getting error “No such module” using Xcode, but th

2018-12-31 15:06发布

问题:

I\'m currently coding in Swift, and I\'ve got an error:

No such module Social

But I don\'t understand, because the module is in my project, declared in \"Linked frameworks and Libraries\" and in \"Embedded Binaries\".

The frameworks is in Objective-C, so I wrote a Bridge Header for it.

Please, how can I make Xcode recognize the framework?

\"Error

\"Project\"

\"Linkes

\"Header

回答1:

I\'m not sure why this happens, but one way to solve your issue is to go into your build settings and defining the Framework Search Paths to a folder which contains the frameworks in question. If the frameworks are placed in your project directory, simply set the framework search path to $(SRCROOT) and set it to recursive.



回答2:

In case it\'s Friday afternoon or anytime after 1am:

Opening xcodeproj instead of xcworkspace will cause an error like this...



回答3:

I am not quite sure why Martin R\'s answer in the comments for the question is so disregarded:

Make sure that you tried simply skipping import of the framework as it is already added with the bridging header.

Hope this helps



回答4:

I had the same issue using Cocoapods and Swift. I didn\'t notice the following lines in the Podfile:

# Uncomment this line if you\'re using Swift
# use_frameworks!

So, all I had to do was change it to:

# Uncomment this line if you\'re using Swift
use_frameworks!

...aaand it worked :)



回答5:

Make sure that the naming of you configurations in the sub projects matches that of the \"parent\" project. If the configuration naming don\'t match exactly (case-sensitive), Xcode will abort the archive process and show the error \"No such module ...\"

That is, if you have a \"parent\" project with a configuration named \"AppStore\" you must make sure that all subprojects also have this configuration name.

See my attached screenshots.

\"Configuration

\"Configuration

\"Configuration



回答6:

Please compare this screenshot with your build setting. It may this work. Go to the framework search path:

\"Enter



回答7:

I was experiencing this problem as well. The fix for me was that the Archive schemes between the two projects didn\'t match. I have an xcworkspace with a framework project and an app project. The problem was that in the Archive scheme for my app, I was using a different Build Configuration than the framework was using for it\'s Archive scheme. I set both Build Configurations to Release, and that fixed the issue.



回答8:

Assuming the Framework really is there and in the path, etc... delete the ~/Library/Developer/Xcode/DerivedData/ModuleCache directory (and clean the project and delete the project-specific derived data for good measure).

When you do the standard cleanup, the ModuleCache directory doesn\'t get rebuilt.



回答9:

In my case, after many attempts to figure out what I was doing wrong importing a framework I eventually discovered that the framework itself was the problem. If you are not getting your framework from a trusted source you should inspect the framework and ensure that it contains a Modules folder with a module.modulemap file inside it. If module.modulemap is not present, you will get the \"No such module \'MyFramework\'\" error.

\"Example

If the Modules folder is missing the \"MyFramework.swiftmodule\" folder then the framework will be found but Xcode won\'t know about its contents so you will get different errors.



回答10:

Be sure, that Find implicit Dependencies in Build options in Scheme is on!



回答11:

I also encountered the same error a few days back. Here\'s how I resolved the problem:

The error is \"module not found\"

  • Create Podfile in your root project directory
  • Install cocoapods (a dependency manager for Swift and iOS projects)
  • Run pod install
  • Go to Project Build Settings:

    • Find Objective-c bridging Header under Swift compiler - Code Generation (If you don\'t find Swift compiler here, probably add a new Swift file to the project)
    • Drag and drop the library header file from left side to bridging header (see image attached)\"enter
  • Create a new bridging header file: e.g TestProject-Bridging-Header.h and put under Swift Compiler → Objective-C Generated Interface Header Name (ref, see the image above)

  • In TestProject-Bridging-Header.h file, write #import \"Mixpanel/Mixpanel.h\"
  • In your Swift file the code should be: Import Mixpanel (i.e name of library)

That\'s all.



回答12:

Ok, how the same problem was resolved for me was to set the derived data location relative to the workspace directory rather than keeping it default. Go to preferences in xcode. Go to locations tab in preferences and set Derived data to Relative. Hope it helps.



回答13:

If you\'re building for a platform like tvOS, make sure you have an Apple TV (i.e. matching) simulator selected.

Building a tvOS app with an iOS simulator selected gave me exactly this error. Spent the better part of an hour looking for all sorts of build issues... doh.



回答14:

In my case the app the IPHONEOS_DEPLOYMENT_TARGET was set to 9.3 whereas in my newly created framework it was set to 10.2

The implicit dependencies resolver ignored my new framework because the requirements of the target platform are higher than the app requirements.

After adjusting the framework iOS Deployment Target to match my application deployment target the framework compiled and linked successfully.



回答15:

The following steps worked for me.

  1. Quit xcode
  2. Run \"pod update\" in terminal
  3. Open .xcworkspace and build again.


回答16:

I was getting same error for

import Firebase

But then noticed that I was not adding pod to the main target section but only adding to Test and TestUI targets in Podfile.

With the command

pod init

for an xcode swift project, the following Podfile is generated

# Uncomment the next line to define a global platform for your project
# platform :ios, \'9.0\'

target \'MyApp\' do
  # Comment the next line if you\'re not using Swift and don\'t want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp

  target \'MyAppTests\' do
    inherit! :search_paths
    # Pods for testing
  end

  target \'MyAppUITests\' do
    inherit! :search_paths
    # Pods for testing
  end

end

So, need to make sure that one adds pods to any appropriate placeholder.



回答17:

I was getting the same error as i added couple of frameworks using Cocoapods. If we are using Pods in our project, we should use xcodeworkspace instead of xcodeproject. To run the project through xcodebuild, i added -workspace <workspacename> parameter in xcodebuild command and it worked perfectly.



回答18:

I fixed this with

Targets -> General -> Linked frameworks and libraries

Add the framework which should be at the top in the Workspace folder. Pain in the arse.



回答19:

I just deleted my cocoapod. Then, I did a pod install to remove it. Then, I just added it back into my podfile and re-installed it. That made it work. Not sure why.



回答20:

I found that the Import Paths in the Build Settings was wrong for a custom (MySQL) module. After pointing that to the right direction the message was gone.



回答21:

Just for completing with another possibility, this error might happen when the option \"Find Implicit Dependencies\" is unchecked. Go to Edit Scheme -> Build.

\"enter

Then check this options.

\"enter



回答22:

I had this problem while developing a custom Pod. Found that I just needed to specify the dependency in my Procfile:

Pod::Spec.new do |s|
   # ... other declarations

   s.dependency \'Alamofire\', \'~> 4.3\'
end


回答23:

I was getting this issue because I set the wrong target in the podfile (the project itself rather than the UITests section).



回答24:

My issue was with multiple targets. I solved it with below links: configure pod file right way and fix build settings

Hope some one will find it helpful.



回答25:

I had already installed pods. Build worked without any problems when I builded application on my device, but archive didn\'t work. I just run:

pod install

no new pods were installed, just .xcodeproj file got regenerated and archive started working



回答26:

If all the above methods did not work for you like in mine case. There was no problem in the previous day but in next morning I faced the same error. I just removed the frameworks by removing references and again added them. I know this may sound silly, but voila it worked.



回答27:

I had similar problem with loading FacebookSDK, I added ~/Documents/FacebookSDK (search where your frameworks are) to Framework search paths in Build settings and after that I was able to import the FBSDKShareKit module



回答28:

For what it\'s worth (I\'m new to this using Xcode 7.2/Swift 2), but I noticed that just having the .swift file from the library in the project directory automatically gives you access to it and does not need the using statement.

Example: I\'m using SwiftyJSON and just having the SwiftyJSON.swift file in the project was all I needed. The using statement was actually giving me the \'no such module\' error and taking it out resolved it, and it works fine.



回答29:

IF you have done everything above and still nothing worked for you then try adding $(inherited) in Framework search path of your target\'s build setting.



回答30:

For me this occurred on RxSwift and the issue was I had fixed it to 3.0.0 in the Podfile. Removing the version restriction and update the pods upgraded it to 3.1.0 which fixed it.



标签: ios xcode swift