When running the command ionic cordova add platform android I am getting the following error.
I've completely uninstalled Nodejs and reinstalled Ionic and Cordova globally from scratch but I can not figure out why this error is occurring.
The error also occurs when I execute the command cordova -v
cordova.cmd platform add android --save
C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:347
throw err;
^
Error: Command failed: wmic os get Caption
Description = O servi�o n�o pode ser iniciado porque est� desativado ou n�o tem dispositivos ativados associados.
at makeError (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:174:9)
at Function.module.exports.sync (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:338:15)
at windowsRelease (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\windows-release\index.js:34:24)
at osName (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\os-name\index.js:39:18)
at new Insight (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\node_modules\insight\lib\index.js:37:13)
at Object.<anonymous> (C:\Users\LUIZ\AppData\Roaming\npm\node_modules\cordova\src\telemetry.js:26:15)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd platform add android --save exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
This error occurs every time I run the command, I can not add the Android platform. I need to run ionic cordova run android to open in my emulator I created in Android Studio.
npm list -g --depth=0
C:\Users\LUIZ\AppData\Roaming\npm
+-- #angular/cli#8.0.2
+-- cordova#9.0.0
`-- ionic#5.0.1
I tried many things, but I had to:
Windows-Key (Keyboard)
System Environment Variable
Environmentsvariables..
Select Path Variable and edit
Add the path to your wbem
example: c:\Windows\System32\wbem
Restart cmd
Enjoy
Related
I am trying to generate an APK of my ionic applications. ionic serve render without errors, but when i run ionic cordova build android it give me this error :
i've already try to uninstall then install cordova without results.
C:\Users\Nacim\AppData\Roaming\npm\node_modules\cordova\node_modules\currently-unhandled\core.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Nacim\AppData\Roaming\npm\node_modules\cordova\node_modules\currently-unhandled\index.js:2:12)
[ERROR] An error occurred while running subprocess cordova.
cordova build android --verbose exited with exit code 1.
Any idea of the root of the issue ?
Uninstaling then instaling ionic and cordova resolve the issue. It was caused by some missing dependancies in cordova and ionic package due to poor internet connexion.
I'm trying to build the default Hello World phonegap project for android on my ubuntu system, but I am confronted by errors at every step.
SHORT VERSION:
I cannot create a phonegap project without sudo (not quite true--see below).
After creating a phonegap project with sudo, I cannot build android without sudo.
When I type "sudo phonegap build android", I lose my path settings, resulting in an error.
I have attempted a fix for this last problem by including the line "alias sudo='sudo env PATH=$PATH'" in.bashrc, as suggested in sudo changes PATH - why?, but it doesn't work. I also added ANDROID_HOME and PATH lines to .bash_profile, with no success.
I think the 'android' command actually is in my path.
Here are the last lines of my .bashrc:
export PATH="$HOME/Android/tools:$PATH"
export PATH="$HOME/Android/platform-tools:$PATH"
export ANDROID_HOME="$HOME/Android:$PATH"
alias sudo='sudo env PATH=$PATH'
I also have the following in ~/.bash_profile:
export PATH="$HOME/Android/tools:$PATH"
export PATH="$HOME/Android/platform-tools:$PATH"
export ANDROID_HOME="$HOME/Android:$PATH"
LONG VERSION:
gregory#gregory-1001PXD:~/javascript$ phonegap create phonetest
Error: EACCES, permission denied '/home/gregory/.config/configstore/update-notifier-cordova.json'
You don't have access to this file.
at Object.fs.openSync (fs.js:432:18)
at Object.fs.readFileSync (fs.js:286:15)
at Object.create.all.get (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:34:26)
at Object.Configstore (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:27:44)
at new UpdateNotifier (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/index.js:34:17)
at module.exports (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/index.js:123:23)
at checkForUpdates (/usr/local/lib/node_modules/phonegap/node_modules/cordova/src/cli.js:64:20)
at cli (/usr/local/lib/node_modules/phonegap/node_modules/cordova/src/cli.js:114:5)
at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/node_modules/cordova/bin/cordova:41:1)
at Module._compile (module.js:456:26)
gregory#gregory-1001PXD:~/javascript$ sudo phonegap create phonetest
[sudo] password for gregory:
Creating a new cordova project.
gregory#gregory-1001PXD:~/javascript$ cd phonetest/
gregory#gregory-1001PXD:~/javascript/phonetest$ sudo phonegap build android
[phonegap] executing 'cordova build android'...
cp: no such file or directory: /home/gregory/javascript/phonetest/icon.png
Running command: /home/gregory/javascript/phonetest/platforms/android/cordova/build
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /home/gregory/javascript/phonetest/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/gregory/javascript/phonetest/platforms/android/cordova/build: Command failed with exit code 2
Bu I think the android command is in my PATH (it tab-completes).
NOTE: I can create a project without sudo if I remove the file update-notifier-cordova.json. But it still produces an error, as follows.
gregory#gregory-1001PXD:~/javascript$ sudo mv /home/gregory/.config/configstore/update-notifier-cordova.json ~/Documents/
gregory#gregory-1001PXD:~/javascript$ phonegap create phonetest
Creating a new cordova project.
gregory#gregory-1001PXD:~/javascript$ cd phonetest/
gregory#gregory-1001PXD:~/javascript/phonetest$ phonegap build android
[phonegap] executing 'cordova platform add --save android'...
Error: Failed to fetch platform android#~4.1.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: EACCES, open '/home/gregory/.cordova/lib/npm_cache/cordova-android/4.1.1/package/.npmignore'
[phonegap] executing 'cordova build android'...
Error: No platforms added to this project. Please use `cordova platform add <platform>`.
This is documented in their JIRA: https://issues.apache.org/jira/browse/CB-10062
Check the ownership of the file using:
ls -al /home/gregory/.config/configstore/update-notifier-cordova.json
If it is root, you may want to try reinstalling cordova - otherwise use the workaround suggested by running:
chmod 744 /home/gregory/.config/configstore/update-notifier-cordova.json
I was trying to build Moodle's ionic mobile app locally on Windows by following the below steps:
cd project-directory
ionic platform add android
The command prompt returns the below error:
Updated the hooks directory to have execute permissions
Adding android project...
Running command: cmd "/s /c "C:\Users\zameer\.cordova\lib\npm_cache\cordova-andr
oid\4.1.1\package\bin\create.bat D:\ionic\moodlemobile2-master\moodlemobile2-mas
ter\platforms\android com.moodle.moodlemobile "Moodle Mobile" --cli""
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.moodle.moodlemobile
Name: Moodle Mobile
Activity: MainActivity
Android target: android-22
Copying template files...
Android project created with cordova-android#4.1.1
Running command: "C:\Program Files\nodejs\node.exe" D:\ionic\moodlemobile2-maste
r\moodlemobile2-master\hooks\after_prepare\010_add_platform_class.js D:\ionic\mo
odlemobile2-master\moodlemobile2-master
add to body class: platform-android
Running command: "C:\Program Files\nodejs\node.exe" D:\ionic\moodlemobile2-maste
r\moodlemobile2-master\hooks\after_prepare\020_add_ios_transport_security.js D:\
ionic\moodlemobile2-master\moodlemobile2-master
module.js:338
throw err;
^
Error: Cannot find module 'plist'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (D:\ionic\moodlemobile2-master\moodlemobile2-master\ho
oks\after_prepare\020_add_ios_transport_security.js:10:13)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Error: Hook failed with error code 1: D:\ionic\moodlemobile2-master\moodlemobile
2-master\hooks\after_prepare\020_add_ios_transport_security.js
Everything seems normal till the below part of the above error block:
throw err;
^
Error: Cannot find module 'plist'
My aim is to run this project locally to see ionic in action
What is this plist module? Why is it not getting detected?
After cloning a Git repository that contains a Ionic app, you need to run these 2 additional commands:
Install Node.js dependencies
npm install
It will install all the Node.js dependencies in the local node_modules folder. The modules considered are the ones listed under dependencies and devDependencies in the package.json file located at the root of the cloned Git repository.
Install Cordova plugins
ionic state restore
This command looks at the cordovaPlugins and cordovaPlatforms attributes in the package.json file and install the additional platforms and plugins code required for the app.
You did not execute npm install so you are missing the required packages.
Read this on what need to be done to work with ionic.
Go into the project folder where the package.json is in and execute the npm install form that folder.
Having first Ionic encounter, I am setting the environment up for an Android app on OSX Yosemite. By running the command sudo ionic platform android I am getting following error:
Error: %s Error: ENOENT, no such file or directory '/Users/myUser/hooks'
at Error (native)
at Object.fs.readdirSync (fs.js:761:18)
at Object.setHooksPermission (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/hooks.js:116:24)
at Object.IonicTask.run (/usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:51:13)
at Object.run (/usr/local/lib/node_modules/ionic/lib/cli.js:95:32)
at Object.<anonymous> (/usr/local/lib/node_modules/ionic/bin/ionic:9:10)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
Updated the hooks directory to have execute permissions
Error happened { [Error: ENOENT, open '/Users/myUser/config.xml'] errno: -2, code: 'ENOENT', path: '/Users/myUser/config.xml' }
Error: ENOENT, open '/Users/myUser/config.xml'
at Error (native)
Versions after running their upgrade:
├── cordova#5.4.1
└── ionic#1.7.12
It should be this,
$ ionic platform add android
Also, you'd better not run command with sudo or you might face with troubles with permission some time later.
please go to myApp folder
then run the command :
ionic platform add android
My android platform was corrupt, after removing it and adding it properly, the issue got solved
go to ionic app folder where your config.xml file exists.and then execute this command.
$ cd Myapp
where folder structure should look like this
$Myapp -> ls
$Myapp -> bower.json gulpfile.js ionic.project platforms README.md scss
config.xml hooks package.json plugins resources www
$Myapp -> ionic platform add android
Here is a PATH in environment :
C:\Users\user\AppData\Roaming\npm;D:\work\SDK\SoftPhonegap\ADT\sdk\platform-tools;D:\work\SDK\SoftPhonegap\ADT\sdk\tools;D:\work\SDK\SoftPhonegap\apache-ant-1.9.5\bin;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Java\jdk1.7.0_51\bin;C:\Program Files\Java\jdk1.8.0_45\bin;D:\work\SDK\SoftPhonegap\ADT\sdk\build-tools
A. Error log of cordova build android
BUILD FAILED
D:\work\SDK\SoftPhonegap\ADT\sdk\tools\ant\build.xml:601: The following error oc
curred while executing this line:
D:\work\SDK\SoftPhonegap\ADT\sdk\tools\ant\build.xml:542: Unable to resolve proj
ect target 'android-21'
Total time: 0 seconds
D:\work\SDK\SoftPhonegap\ADT\hello\platforms\android\cordova\node_modules\q\q.js
:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "ant debug -f D:\work\SDK\SoftPho
negap\ADT\hello\platforms\android\build.xml -Dout.dir=ant-build -Dgen.absolute.d
ir=ant-gen"
ERROR building one of the platforms: Error: D:\work\SDK\SoftPhonegap\ADT\hello\p
latforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: D:\work\SDK\SoftPhonegap\ADT\hello\platforms\android\cordova\build.bat: C
ommand failed with exit code 8
at ChildProcess.whenDone (C:\Users\user\AppData\Roaming\npm\node_modules\cor
dova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
B Error log of Ant
C:\Users\user>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_45\lib\tools.jar
Buildfile: build.xml does not exist!
Build failed
C. when add platform android
D:\work\SDK\SoftPhonegap\ADT\hello>cordova platform add android
npm http GET https://registry.npmjs.org/cordova-android/3.7.2
npm http 304 https://registry.npmjs.org/cordova-android/3.7.2
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.example.hello
Name: HelloWorld
Android target: android-21
Copying template files...
Project successfully created.
Installing "com.phonegap.plugins.PushPlugin" for android
Installing "com.salesforce" for android
Installing "org.apache.cordova.device" for android
Could not run SalesforceMobileSDK plugin android pre-install script
You are running node v0.10.25
You need to be running node 0.12 or above
You won't be able to successfully run: cordova build
Running SalesforceMobileSDK plugin android post-install script
The "android" utility does not exist at D:\work\SDK\SoftPhonegap\ADT\sdk\tools;D
:\work\SDK\SoftPhonegap\ADT\sdk\platform-tools\tools\android.bat. Make sure you
've properly installed the Android SDK.
I think you need to give platform_tools pah also, you should post your error log,
anyway here is how my PATH looks like
C:\Users\amitabhs\AppData\Roaming\npm;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platform-tools;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\tools;F:\Softs\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\adt-bundle-windows-x86_64-20140702\sdk\platforms;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\apache-ant-1.9.5\bin;
check if it helps
Compile your project in https://build.phonegap.com/
There you have no problems with OS and can compile for all OS.
I use then for IOS compilation.
Solution:
Uninstall node v0.10.25
install node 0.12 or above
remove platform android (cordova platform rm android)
add platform android (cordova platform add android)
build android (cordova build android)
Done