Cordova ios project missing cordova.js - ios

I have a cordova ios project that I created a while ago with cordova 2.8.x and now I have updated cordova to 3.3.1
The problem is that when I execute cordova build, no cordova.js file gets created. I've played around with cordova 3.3.1 and it seems that the cordova.js file is created when the platform is added.
I've already have added the platform from before, how can I create the cordova.js file for ios without readding the ios platform?

If you create your project with phonegap create myApp it creates it with phonegap.js instead of cordova.js
You can try cordova platform add <your platform> e.g. cordova platform add ios should add cordova.js to your project.
Also, make sure your index.html <script> is referencing the correct file after doing the above.

just take care of building your project because if you build your project using:
phonegap local build ios
phoengap.js file will be generated but if you build it using:
cordova build ios
cordova.js file will be generated

Related

Required cordova.js file not found. Cordova plugins will not function! Capacitor: FATAL ERROR

I updated my Ionic 2.5 App to Ionic 4.
The app was building on iOS as expected but when I ran it, it was throwing me this error: "Required cordova.js file not found. Cordova plugins will not function! Capacitor: FATAL ERROR".
I tried
removing all Cordova plugins
disabling angular buildOptimizer and optimization
After some struggle I figured out that the "public" folder wasn't present in the Xcode project. According to this article we must remove and re-add the public folder.
Apparently ionic builds the web and scripts into www folder and then copies them to iOS/App/App/public folder. Since the files weren't in that folder the app wasn't able to process those riles.

Can't build Cordova iOS project using CLI but can build/run the Xcode project

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.

Cordova project can't remove plugin after update my project

I am trying to upgrade my Cordova Ionic project ios platform from 3.0.1 to the newest 4.5.2 using xcode 9. I remove the ios platform and re-add it again under CLI 7.1.0. Then I restore all the .xcodeproject settings by copy the old .xcodeproject into the new ios platform and reset all the path necessary in the workspace. Luckily my project build successfully and runs fine in the debug mode.
However when I am trying to upgrade some out of date plugins in the new project, I found that I can only "add" plugin, which everything just goes fine. But when I am trying to remove any plugin (whether they have been added in the new workspace or not), the CLI always show red font message: Error: Could not find *-Info.plist file, or config.xml file.
This message will also show up if I tried to run ionic prepare ios command. Interestingly enough, if I use the .xcodeproject file cordova originally generated, then all the things will just work fine.
Any idea on what specific settings is wrong so that the CLI could only recognize the new .xcodeproject file but not the old .xcodeproject file?
To answer "why don't want to use the new .xcodeproject automatically generated". My project is pretty huge which contains 4 different targets and each of them have different project settings. First of all, CLI don't know that and will only generate one target and I have to duplicate it another 3 times. Secondly, it will be such a pain to restore each target settings one by one. And thirdly the new project doesn't contain any changes in the iOS native code I made such like in appDelegate class. Therefore I just want to find a trick way to make it through.
Cordova creates the files automatically, I believe copying a file generated from an old version and pasting a new one will break your project.
What happens if you remove the platform, add again but without reusing the .xcodeproject? The normal thing is that you got to work normally.
Another option would be to upgrade Cordova or a downgrade, using nvm you can have several versions of Nodejs and Cordova.
You didn't mentioned in your question how you are removing the ios platform , try to do them as follows:
cordova platform remove ios
cordova platform list here you can verify that ios platform deleted
cordova platform add ios --save
I don't know what version you are using but cordova 6.5.0 should solve the ios-build issues. you can install using like below:
sudo npm i -g cordova#6.5.0

Cordova iOS App which is the right www folder?

I am trying to build a Cordova app. All is set up fine, but I am confused now.
There is a www folder in the main folder which is displayed in Xcode. But there is a second in platforms/iOS. This folder is used when I am building the app.
Is that the way it should work? Or can I tell Xcode to take the other folder and not the www in root?
THANKS!
EDIT: And where to locate config.xml? Because in root the iOS App will not find any plugin e.g.
EDIT2: Got that with plugins! Have to install them over terminal
Yes this is a way Cordova is working.
The www in the main folder is the place where you have to implement you changes if you willing to support more then one platform. That folder copied to the platforms/ios/www each time when you run cordova prepare ios and this is actual folder which will be bundled with you iOS application. You you made changes in you main www folder and forget to run cordova prepare ios then you would not see you changes in you application if you run it. You have to run cordova prepare after making changes in the www in the main folder of you app.
Note: If you using cordova build or cordova run then you don't need to call cordova prepare, these commands will call it internally during the run.
As of Cordova 3.5 folder www in the Xcode which you see is same folder which is located in you main appication folder, and folder Staging->www in XCode is folder pointing to platforms/ios/www folder created by cordova prepare for you.
Before Cordova 3.4, www folder in XCode was pointing to platforms/ios/www folder.
I would recommend you made changes in www subfolder of you main folder and run cordova prepare\build\run to build/run your application if you plan to mainly work with HTML + JS or your application would support more then one platform. Otherwise, if you app is strictly iOS you could made you changes directly in Staging->www inside XCode and test you changes immidiately
You could start reading about development path with Cordova here: http://cordova.apache.org/docs/en/3.5.0/guide_overview_index.md.html#Overview_development_paths
More information about using Cordova CLI is here:
http://cordova.apache.org/docs/en/3.5.0/guide_cli_index.md.html#The%20Command-Line%20Interface for explanation of the workflow.
www folder in root level has html, javascript etc. When you build your code, same www folder for each platform will be created. So If you make any code changes in main www folder. You should rebuild the code for specific platform each time. Then only your changes in the main www will be applied in the platform specific www folder.

Where can we place config.xml in IOS phone gap?

Hi I am new to IOS and Xcode. Can we use config.xml in IOS xcode? If we are using where can we place the config.xml. While creating my project I did not get config.xml. Is it will be a problem?
Using the latest versions of cordova tipically update the required files (config.xml) for you when you use the CLI with command
Cordova plugin add
The documentation explain specific tweaks to the config.xml
http://cordova.apache.org/docs/en/3.1.0/config_ref_index.md.html#The%20config.xml%20File
From the doc
For projects created with the Cordova CLI (described in The Command-line Interface The Command-line Interface), this file can be found in the top-level www directory. Using the CLI to build a project regenerates versions of this file in various subdirectories within platforms .Ifyou usetheCLI to create a project, but then shift your workflow to an SDK, the platform-specific file serves as a source.

Resources