25

I added Cordova as a component to my iOS project. Adding a custom plugin leads to the error, despite that the plugin works in a Cordova-only project:

'CDVPlugin.h' file not found

The problematic part is as follows:

#import <Foundation/Foundation.h>

#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#else
#import "CDVPlugin.h"
#endif

What am I missing?

Michael Schmidt
  • 3,391
  • 5
  • 34
  • 39

9 Answers9

57

For xcode7 add "$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include" to your Header Search Paths (and you may need to set Enable Bitcode to No - was necessary for me, but may be related to different problem with xc7)

Marek Jalovec
  • 1,427
  • 11
  • 12
  • 2
    Right on time! this is the correct answer. Thank you Kind Sir! – jlstr Oct 28 '15 at 16:14
  • Just adding "$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include" to my Header Search Paths solves the issue in my case. Enable Bitcode remains to YES. To be noted the issue is appeared after an update of Xcode from a previous version 7 to Version 7.1 (7B91b) – Lisarien Oct 30 '15 at 14:24
  • As @Lisarien said, it's not necesary to enable BitCode. Just adding the right path do the job ! It's worked for me ! – Dam Fa Nov 19 '15 at 00:27
  • you made my day sir! Thank you! – Massimo Polimeni Nov 25 '15 at 14:38
  • No works for me, my bit code NO and string `"$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include"` too no work –  Jan 31 '16 at 00:36
  • This worked for me, after Enable Bitcode set to No. Thanks. – leonsas Mar 11 '16 at 18:24
  • Upgrading my cordova iOS version was the solution for me. – im3r3k Mar 11 '16 at 19:11
  • This issue is coming back up in Xcode 8 with server 5.4, but only from an Xcode bot. Building locally still works fine. – Chris Sep 15 '16 at 19:49
24

Click on the project icon in the Project Navigator,

select your Project, then select the "Build Settings" tab

Enter "Header Search Paths" in the search field

Add "$(CORDOVALIB)/Classes" and check the Recursive checkbox - for the Header Search Paths value

optional Add "-all_load" and "-Obj-C" - for the Other Linker Flags value

see detailed description (step 17)

Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
user513790
  • 1,225
  • 1
  • 13
  • 22
  • https://github.com/purplecabbage/GDCordova/blob/master/docs/How%20to%20Use%20Cordova%20as%20a%20Component.md – daserge Mar 12 '16 at 14:27
22

Change your header file to:

#import <Cordova/CDVPlugin.h>

it is working in my application.

AndiDog
  • 68,631
  • 21
  • 159
  • 205
vishnu
  • 229
  • 2
  • 2
21

I had this issue using Cordova. Come to find out my CordovaLib folder under the ios platform directory vanished.

I did:

cordova platform remove ios

then

cordova platform add ios

...and this fixed the issue.

Post Impatica
  • 14,999
  • 9
  • 67
  • 78
5

I have spent awful lot of time trying to fix the same issue in my project, so let me share my findings. It might be relevant for those who are able to build the project in one configuration, but in another configuration (e.g. when building unit tests) precompiler fails to find CDVPlugin.h.

You have to make sure that CordovaLib sub-project has the same set of configurations as your main project.

  1. Select the main project in Xcode in project navigator.
  2. Click on the project icon (above the Targets).
  3. Select Info tab.
  4. Expand Configurations.

So, this is a set of your app configurations. In my example it looked like this: App configurations

You need to have the same set of configurations in your CordovaLib sub-project.

  1. Select CordovaLib sub-project.
  2. Click on the project icon (above the Targets).
  3. Select Info tab.
  4. Expand Configurations.
  5. Make sure you have the same set of configurations as in the main project. If some configurations are missing:
    1. Click + button.
    2. Select Duplicate "Release" Configuration
    3. Give the right name for configuration. Copy-paste it from main project settings.

Now perform a clean build.

pjuzeliunas
  • 1,596
  • 1
  • 15
  • 19
1

Note: Phonegap 2.9.1 (Nov 2013))

I encountered the same problem while trying to make an open source "C" phone gap plugin work. The solution was to add the Cordovalib.xcodeproj to the target project, once done, click on your_project.xcodeproj - you will need to look in the Target Settings, under the Build Phases Tab, make sure that Cordovalib is added in Target Dependencies.

Once done it should allow the statement: #import to work.

Paulo
  • 1,245
  • 10
  • 8
0

Have a look at my answer here:

I had the same problem while installing the ShareKit plugin on Xcode 4.5, cordova 2.1.0 & JQM 1.2.0. The problematic block was:

#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVPluginResult.h>
//#import <Cordova/JSONKit.h>

#else
#import "CDVPlugin.h"
#import "CDVPluginResult.h"
#import "JSONKit.h"
#endif

What worked for me is commenting out the #ifdef line as well as commenting out the whole #else block.

Also, the #import line was already commented out in the source code that I downloaded with the plugin, so I didn't bother messing with that.

Might be of some help to you.

Community
  • 1
  • 1
A_B
  • 527
  • 4
  • 10
0

In xcode 8 and 8 + simply commenting the line worked for me:

#import ...

This is specifically useful if you are trying to extend IOS app build using ionic or cordova to have watchkit or widget control natively.

RohitAneja
  • 966
  • 12
  • 15
-1

replace

import

with (

import "Classes/CDVPlugin.h"

OR

import "CordovaLib/Classes/CDVPlugin.h")

bill
  • 9