I'm running Cordova 3.4.1 and decided to update the one and only plugin I have, Console. I did based on the update to plugins dated April 23, 2014 ( http://cordova.apache.org/news/2014/04/23/plugins.release.html ).
Updating is done by first removing and then adding back the plugin. In other words:
cordova plugin rm org.apache.cordova.console
cordova plugin add org.apache.cordova.console
I then ran
cordova build
which does a lot of voodoo, after which I compiled and ran the app on iOS via Xcode.
The result is this fail: every time my code calls console.log I get this error in the XCode debugger output
CDVPlugin class CDVLogger (pluginName: Console) does not exist.
ERROR: Plugin 'Console' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
-[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
"INVALID",
"Console",
"logLevel",
[
"LOG",
"text i want to see"
]
]
Plainly the process of updating plugins is not working properly. How can fix this myself? And if I do will it effect any subsequent fix by the Cordova team?
FWIW: I repeated this process, tried an cordova platform update ios to no avail. I am loath to reinstall the entire thing given all the mysterious Xcode configuration and build stuff and hoping there's a simple fix...
I diff'ed the project against an earlier version I'd kept that worked properly and came up with this fix:
In Xcode, under your Phonegap or Cordova project, select
Target -> Build Phases -> Compile Sources
Add your plugin into the list there, in this case CVLogger.m located in your file structure under "Plugins".
After this, the project compiles without error and the console plugin works. No need to reinstall and reconfigure your entire project for this...
Related
I'm currently stuck on a problem related to my Ionic project.
I have an Ionic project on GitHub which i've been working on in the past few weeks, i have a few Cordova plugins as part of the project.
When downloading the project from GitHub, i can run the app using Ionic Serve without a problem. However, when trying to setup the project for xCode to run on local device(s), i run into a multitude of errors
Some include:
When running ionic 'cordova platform add ios' the following error appears
Error: Could not install from "ios" as it does not contain a package.json file.
When trying to run 'ionic cordova run ios -l --external'
Error: Error: terminating with uncaught exception of type NSException
I have not yet tried to transfer my code into a new Ionic project, as i wish to see if my problem can be solved without that hassle.
View project code here: https://github.com/designsheikh/bitsandbobs.git
I figured it out. You have the exact same issue I've had with the android platform.
As I pointed it out in the comments, it is indeed caused by a "corrupted" project architecture.
How it happened
Initially, I had an issue with the cordova generated resources, somehow not being copied into the android platform directory. I tried plenty of things with the cordova-res CLI, including using the --copy and the --ios-project flags to force the copy to happen in the directory of my choice.
I couldn't manage to fix my issue, and then decided to rollback all my changes and start over on a clean project to try something else. Since then, I was not able to add the android platform anymore. Every single time, the following error was being thrown :
Error: Could not install from "android" as it does not contain a package.json file.
Explanation
With all my testing, I noticed that when using cordova to add the platform or copy the resources over, somehow, it had created the android platform in the wrong directory, at the root of my project instead of in the platforms folder. And that's where the issue comes from.
I can't explain it, but you will encounter this error every single time if you try to add a platform with cordova while having a folder with this platform name at the root of your project. I have no idea why this would prevent a platform from being added to the project, maybe this folder is used as a temp folder by the CLI.
Solution
The fix is to simply remove any ios or android directory at the root of your project.
The error will go away and you will be able to add the platform again.
#CodingJunkie
Regarding the Github repository you provided in your post, you will likely run into another error while trying to add the ios platform if you use cordova#>=9.0.0.
Using "requireCordovaModule" to load non-cordova module "xcode" is not supported.
Instead, add this module to your dependencies and use regular "require" to load it.
Check this issue#1033 for a workaround. However, it's not recommended to directly edit the plugin source code, you might want to look for another cordova Firebase plugin.
I also noticed you kinda mixed up cordova and capacitor in your project.
Make sure to use one or the other to avoid potential errors.
Hope this helped !
#Reqven
Thank you for your support! - i was sure that i had done this step while trying to fix the issue. It is such an absurd problem, it seems that there is a new project architecture as you mentioned which needs to be followed. I followed your steps with also one minor additional step as im working on the iIOS platform:
Delete iOS folder
cordova platform add ios
cordova prepare ios
ionic build
If step 2 throws an error causing the version not to be found or integrated into the project run - include '#latest' this also solved my problem
Absolutely new to Cordova. These are the steps I've done:
Checked out an existing project
run cordova build ios
The above generates this build error:
(node:10242) UnhandledPromiseRejectionWarning: Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "ios" does not appear to be a valid cordova platform. It is missing API.js. ios not supported.)
I've Googled for a solution to the above and the general consensus seems to be to remove and then add the iOS platform.
Now there's a problem with that. Looking through the commit history, I can see that there have been code changes done to files within the platforms directory so I can't just remove it, or...
Question 1)
Can I?
Question 2)
Is it right to make code changes within the platforms directory? Because it seems like those are generated directories.
Question 3)
Why is it that when I open the Xcode project under platforms/ios, I am able to build/run it fine despite the Cordova CLI error above?
it's not right to manually edit the platform files. And some manual changes might make the project not build, so might be related to the manual changes somebody did. So if you don't want to risk to remove the platform, continue building from Xcode
from root www to platforms/ios is transferred by cordova commands such us cordova prepare ios or cordova build ios or cordova run ios.
So if you can't do a cordova prepare ios because of that error you can try a few things.
Copy your files from www to platforms/ios without replacing the whole folder, just the duplicate files. cordova prepare ios is not just a copy, it's also does some modifications/aditions, but if you don't remove existing files it might work.
Create a new project and copy the platforms/ios/cordova to your own project and see if that fixes the mentioned problem, as that's where the Api.js file is.
Downgrade the Cordova CLI, try to latest 7.x.x and if it doesn't work, try with latest 6.x.x, one of those won't require the Api.js as it relatively new.
I updated all the plugins I was using in cordova using the remove and add method.
cordova plugin rm org.apache.cordova.device
cordova plugin add org.apache.cordova.device
....
I then prepare and build
cordova prepare ios
cordova build ios
I test the app on the simulator and I get:
ERROR: Plugin 'Device' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml
Why is this happening? I was under the impression that the command line was going to update everything automatically, what am I missing?
Before the rm and add everything was working fine.
Thank you for your time.
If anyone stumbles on this, I found the solution.
After updating, adding or removing plugins, you should always do this:
cordova platform rm ios
cordova platform add ios
That will fix any issue.
I am getting build error while I am removing the plugin through Cordova CLI and again add the same plugin. Anybody can help me why I am getting error?
Thanks in Advance :)
Hi myself found the issue. While I am adding plugin to cordova iOS project, required frameworks also getting added to the XCode Project (Frameworks mentioned in plugin.xml). And while I am removing the plugin, the framework already added still remains in the XCode project navigator window. When again I am adding the plugin, cordova not adding the framework to this project hence getting the build error.
Solution
Run Cordova remove plugin through CLI
Manually remove the unused framework reference from the xcode project.
Add the plugin through Cordova CLI
I think this is either a Cordova or XCode bug. This error is inconsistent and its is happening sometimes. I got this error while developing & testing custom Cordova plugin.
I just installed the cordova file plugin and it completely breaks my application with this error:
ERROR: Method 'requestAllPaths:' not defined in Plugin 'File'
After googling for several variations of this topic I wasn't able to find anything that addresses this issue. Any ideas?
I am using Cordova 3.5.0 with the file plugin added like this:
cordova plugin add org.apache.cordova.file
I tried adding the optional configuration described in the readme on github but that didn't change anything.
This is the error code that I am getting when I run:
cordova run ios
[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
"File1936338184",
"File",
"requestAllPaths",
[
]
]
I am absolutely clueless as to why this is happening or where.
Somewhere in the App you are making a call to requestAllPaths.
As far as the File API documentation goes there is no such method as requestAllPaths
There is an API called requestFileSystem.
Hope it helps to debug your app
edit1:
You can have a look here for a similar issue.
Actually, the error happens if the plugin was already added to your project : in that case, it seems that the Cordova build process only updates the javascript interface but not the underlying native iOS sources, which explains the missing code :(
To fix it, you should remove the plugin beforing adding it :
cordova plugin rm org.apache.cordova.file
cordova plugin add org.apache.cordova.file
Be aware though that you might run in some additional issues : even if the files are properly updated in your platforms/ios/project_name/plugins directory, they might not be properly referenced in xcode => cf. cordova 3.4 with xcode 5.1 won´t build with latest file-transfer plugin
Hope it helps,
Cheers,
D.