Cannot build project for iOS from cordova cli - android

I've created a project using Cordova CLI, version 3.5.0.
I've successfully deployed the project for Android platform by using the CLI.
cordova run android
However, I'm having problem to deploy the project for iOS.
cordova run ios
I encountered this error:
mv: dest file already exists: /Users/amirfazwan/Documents/workspace/MyPKS/platforms/ios/MYPKS/MyPKS-Info.plist
mv: dest file already exists: /Users/amirfazwan/Documents/workspace/MyPKS/platforms/ios/MYPKS/MyPKS-Prefix.pch
shell.js: internal error
Error: EINVAL, invalid argument '/Users/amirfazwan/Documents/workspace/MyPKS/platforms/ios/MYPKS.xcodeproj'
at Object.fs.renameSync (fs.js:543:18)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/shelljs/shell.js:495:8
at Array.forEach (native)
at Object._mv (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/shelljs/shell.js:471:11)
at Object.mv (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/shelljs/shell.js:1491:23)
at pbxProject. (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/ios_parser.js:126:27)
at pbxProject.EventEmitter.emit (events.js:98:17)
at pbxProject. (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/xcode/lib/pbxProject.js:30:18)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at handleMessage (child_process.js:322:10)
This problem only occur after I access the Xcode project manually to add the Icon & splash screen since the icon & splash screens are not automatically added to the project even though declared in config.xml.
I've tried to remove the Info.plist & Prefix.pch file, but then this error appeared.
Error: ENOENT, no such file or directory '/Users/amirfazwan/Documents/workspace/MyPKS/platforms/ios/MYPKS/MYPKS-Info.plist'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at Object.exports.parseFileSync (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/plist-with-patches/lib/plist.js:18:19)
at Object.module.exports.update_from_config (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/ios_parser.js:66:31)
at Object.module.exports.update_project (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/ios_parser.js:189:21)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/prepare.js:113:31
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:760:13)
The project works just fine if launched from Xcode, but I no longer can build the project from CLI or launch the "serve" command from CLI for debugging purpose.
Please guide me, thanks.
SOLVED
Solved by renaming the project name using Xcode. Thanks Jason for the tips.

Just remove the platforms and then add them again.
cordova platform rm ios
cordova platform rm android
cordova platform add ios
cordova platform add android

EDIT: Try this other solution first! It works for most issues: https://stackoverflow.com/a/28300528/1250444
I struggled with this as well. Finally found a solution by trial and error. D:
What happened for me was renaming the project name to have capitals. This caused all sorts of confusion for Cordova.
The first thing I did was rename the problematic plist and pch files to match the correct capitalization. So, in your case, if it was myPKS, but now is MyPKS, you'd need to rename the files to be MyPKS-Info.plist and MyPKS-Prefix.pch.
I then had to rename the .xcodproj to match capitalization.
After that, another issue happened:
xcodebuild: error: The project 'NewName.xcodeproj' does not contain a target named 'NewName'.
To solve this, I had to rename the target to have the proper capitalization as well. Since I'm new to iOS dev, I have not idea how to describe how to get there. I just finally stumbled upon it, made the change, and it worked!
Best of luck!

What solved my problem was by doing the following
Removing the ios platform; ionic platform remove ios
Removing the android platform; ionic platform remove android
Adding the Ios platform back; ionic platform add ios
Adding the android platform back; ionic platform add android
Rebuild; ionic build
Hope this helps anyone else.

Jason Cox's answer helped me - but I did not rename any files, I just had to change the name of the app in my config.xml
<name>myApp</name>
to
<name>MyApp</name>

This worked in Meteor 1.3.x
Remove a particular platform and re-add again via meteor command via console.
For ex.
meteor list-platforms
meteor remove-platform ios
meteor add-platform ios

I got this same error. The reason why this happen to me was because i changed the name in the xml from myapp to MyApp. It worked again once i changed it back to the old name.
Renaming in xcode also worked so thanks for that.

Related

CordovaError: Project name must not begin with a number

I'm building an app which name starts with a number "100 Times". But when I try to add the Android platform:
ionic cordova platform add android
I get the following error:
CordovaError: Error validating project name. Project name must not begin with a number
My config.xml is like:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.myapp.times100" ...>
<name>100 Times</name>
...
</widget>
As far as I know it is not a Google Play restriction, cause there are a lot of apps with names that starts with numbers.
How can I use an application name that starts with a number with Cordova?
I was able to use numbers at beginning of my app name following the steps below:
Create the android studio project running "cordova prepare android"
Open the Android Studio Project and edit "res/values/strings.xml"
Replace the "app_name" node content with the name you want.
Build the APK using Android Studio.
That's a cordova bug. There is an issue for that:
https://github.com/apache/cordova-android/issues/584
There's also a pull request to fix it in version 9.x of cordova-android:
https://github.com/apache/cordova-android/pull/859
For now the only way is to use some (hackish) workaround to fix that.
I generate the apk in a CI environment using docker containers, so executing commands manually in Android Studio was out of question in my case, so I forked the cordova-android repo, commented the lines that does that unnecessary (and wrong) validation and installed the android plugin in my project from the forked github repo.

Plugins are not always added after cordova add platform android and iOs

I need to run ionic platform add android/iOs few times to get the desired result.
Sometimes plugins are added after first run, but usually I have to wipe out the plugins and platform directories and re-run adding the platform cycle few times until all plugins are added to android folder.
Did anyone else experienced same problem and if yes - what is the resolution?
if any ...
thanks in advance
I've experienced some similar problems myself. Try reseting your ionic project:
ionic state reset
This removes the platforms/ and plugins/ folder and restores them from the information stored in your package.json. There's a few other useful commands documented on the ionic-cli project.
The solution that I ended up using is to uninstall and reinstall all the plugins after adding the platform. Since I've had trouble with this issue in past Cordova apps, I'm trying to make the builds as consistent as possible, so I'm not committing the platforms directory and deleting it after I build the apk. I've done this with a script:
ionic platform add android
ionic plugin remove org.apache.cordova.device
ionic plugin remove org.apache.cordova.console
ionic plugin remove com.ionic.keyboard
ionic plugin add org.apache.cordova.device
ionic plugin add org.apache.cordova.console
ionic plugin add com.ionic.keyboard
platforms/android/cordova/build --release
rm -rf platforms
This has consistently worked for me, but since I'd rather not have to worry about keeping this current, I have moved these commands into the: after_platform_add/010_install_plugins.js, with the following additions:
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
packageJSON.cordovaPlugins.forEach(function(plugin) {
exec('cordova plugin remove ' + plugin, function(error, stdout, stderr) {
sys.puts(stdout);
});
});
packageJSON.cordovaPlugins.forEach(function(plugin) {
exec('cordova plugin add ' + plugin, function(error, stdout, stderr) {
sys.puts(stdout);
});
});
This assumes that something along these lines exists in the package.json in the root JSON object:
"cordovaPlugins": [
"org.apache.cordova.console",
"org.apache.cordova.device",
"com.ionic.keyboard"
]
Which should occur automatically if the after_plugin_add/010_register_plugin.js is working properly.
All that said, I feel like this is kind of hacky and that Ionic should be handling all this properly, so hopefully I can find some time to look into this issue on that side of things and find the root issue of this problem.
I think I have found solution to this issue. Instead of using ionic cli for adding platform I'm using sudo cordova platform add .... It's working every time.
It is better now to use ionic cordova prepare
This installs and configures all plugins in a single step

cordova platform add android new error

I hit the following error while executing cordova platform add android:
c:\users\demolition hammer\hellox> cordova platform add android
creating android project...
C:\users\demolition' is not recognised as an internal or extrenal command, operable program or batch file
error: c:\users\demoliton hammer\.cordova\lib\android\cordova\3.4.0\bin\create.
bat:command failed with exit code 1
at childprocess.whendone <c:\users\demolition hammer\appdata\roaming\npm\node_modules\cordova\src\superspawn.js:126:23>
at childprocess.eventemitter.emit <events.js:98:17>
at maybeclose <child_process.js:743:16>
at process.childprocess._handle.oneexit <child_process.js:810:5>
I accidentally deleted the default path of the environment system variable. I have entered a default path for my PC. Apart from that, other paths should be fine. Kindly help me out. This is very frustrating.
a well known problem with the Cordova CLI is that it does not support spaces in the path. Sometimes. In some commands, the path string is properly sanitized. In others, not so much.
Create/Move your project to a directory with alphanumeric characters only and it should work fine.
You could also use the PhoneGap CLI, which has parallel core functionality, but also allows you to upload to PhoneGap build. It handles paths with spaces properly. If it doesn't, I can fix it as I'm the primary maintainer :P

Add FacebookConnect to cordova in netbeans

I'm using cordova with the latest Netbeans build 7.4, which has the cordova integration included.
I added the following line to nbproject/plugins.propteries and can clearly see, that the plugin is fetched:
Calling plugman.fetch on plugin
"https://github.com/phonegap/phonegap-facebook-plugin.git" Fetching
plugin "https://github.com/phonegap/phonegap-facebook-plugin.git" via
git clone
After that, the build crashes, due to missing info:
Error: Variable(s) missing: APP_ID, APP_NAME
Where can I add the missing info, which is the correct file and syntax?
I have found a good tutorial here, which has solved my problem.

CordovaResourceApi import unresolved phonegap

I am using phonegap-2.9.0 with file plugin. When I build project for android platform it creates two packages within the src/ folder:
org.apache.cordova.file
org.apache.cordova.filetransfer
I get below errors within these two packages:
1 - org.apache.cordova.file.FileUtils
Method testSaveLocationExists() from the type DirectoryManager is not visible
Method getFreeDiskSpace() from the type DirectoryManager is not visible
Method testFileExists() from the type DirectoryManager is not visible
2 - org.apache.cordova.filetransfer.FileTransfer
import org.apache.cordova.CordovaResourceApi unresolved
import org.apache.cordova.CordovaResourceApi.OpenForReadResult unresolved
Could someone please tell me what I should do to resolve these?
Thanks.
You have two problems.
1) Version of Phonegap is outdated
2) The way to install a plugin is:
-> phonegap plugin add "urlofplugin" or "/path""
-> phonegap platform add android
-> phonegap prepare
-> phonegap build
sometimes the plugin has a different default installation, the files need to change the platform.
Well, I dont know if I can help you, but I had similar problems. When I installed exactly those two plugins I got an error too. A different one, which I dont perticularly remember, something to do with a missing file that I can easily find in the file manager. Anyway, what helped me was:
I updated to a more recent version, if you are able to I advice for it.
After installing the plugins through cordova cmd api (.nodejs command prompt ... you know what I mean) I was forgetting to build in the api itself. It sounds stupid but I was using wp8 and thus using a template for visual studio. The studio gave me the error, the building process (in cmd) also gave errors, but it was fixed by updating to the newer version.
You need to configure you build path and then add library from external source and select the library then it will resolve or u can make copy and paste cordova library .jar file in your lib folder. then it will remove, if not happen then tell me .......
I am not sure if that will work but first uninstall these plugins using phonegap/cordova CLI and than reinstall it in the root of application folder using the CLI only like this:
phonegap local plugin add <required plugin>
This worked for me after reinstallation.

Categories

Resources