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
2
Answers
@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:
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
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 thecordova-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 :Explanation
With all my testing, I noticed that when using
cordova
to add the platform or copy the resources over, somehow, it had created theandroid
platform in the wrong directory, at theroot
of my project instead of in theplatforms
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 atemp
folder by the CLI.Solution
The fix is to simply remove any
ios
orandroid
directory at theroot
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 usecordova@>=9.0.0
.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
andcapacitor
in your project.Make sure to use one or the other to avoid potential errors.
Hope this helped !