I was using phonegap 2.9 for development, it was pretty easy installing that but, phonegap 3.0 uses some nodejs and command line for installation. I found this tutorial but I am stuck at one step. untill this line,
npm install -g plugman.
it is working, but after this step there is a line,
Then change to the working directory to the project directory.
I can't figure this out and getting an error when i run
cordova -d platform add android
This is the error i am facing,
C:\Users\Comp\AppData\Roaming\npm\node_modules\cordova\src\util.js:57
throw new Error('Current working directory is not a Cordova-based
^
Error: Current working directory is not a Cordova-based project.
at Object.module.exports.cdProjectRoot (C:\Users\Comp\AppData\Roaming\npm\no
de_modules\cordova\src\util.js:57:19)
at CLI.platform (C:\Users\Comp\AppData\Roaming\npm\node_modules\cordova\src\
platform.js:35:36)
at new CLI (C:\Users\Comp\AppData\Roaming\npm\node_modules\cordova\src\cli.j
s:109:30)
at Object.<anonymous> (C:\Users\Comp\AppData\Roaming\npm\node_modules\cordov
a\bin\cordova:41:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
Any help would be appreciated.
I think you haven't created a new project with:
cordova create [PATH] [ID] [NAME]
This will create a
.cordova, platform and www folder.
Things are a bit different when you use 3.3, you won't have a .cordova folder in that case but that doesn't really matter.
After running the create command you should add the android platform (after cd-ing into the path you entered with the cordova create command) with "cordova platform add android".
Now you should copy the contents of your 2.9 app www folder to the www folder Cordova created.
After running "cordova build android" you will notice that it copied the www folder to "platforms/android/assests/www", you should never change things here because running the cordova build android command will overwrite it.
More info on the following page: http://cordova.apache.org/docs/en/3.2.0/guide_platforms_android_upgrading.md.html#Upgrading%20Android
Related
I have a jenkins job that is supposed to create a cordova app but it's failing some reason that I can't quite identify. The jenkins job simply does this:
cordova platform add android
cordova prepare android
cordova build android --debug --verbose
The first command (cordova platform add android) is resulting in the following error:
ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
Error: ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
at Object.mkdirSync (fs.js:738:3)
at Object.module.exports.makeDirSync (/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13)
at /Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/cordova-android/lib/create.js:231:16
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova prepare android
(node:23901) ExperimentalWarning: The fs.promises API is experimental
Discovered platform "android". Adding it to the project
EEXIST: file already exists, mkdir '/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/platforms'
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova build android --debug --verbose
(node:23902) ExperimentalWarning: The fs.promises API is experimental
No platforms added to this project. Please use `cordova platform add <platform>`.
CordovaError: No platforms added to this project. Please use `cordova platform add <platform>`.
at Object.preProcessOptions (/Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:275:15)
at /Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/build.js:29:31
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
Build step 'Execute shell' marked build as failure
When I look inside the platforms directory on the jenkins box it is empty. It is able to create the platforms folder itself, just nothing else under. It doesn't seem to be a permission issue as far as I can tell. If I ssh into the box as the same user that jenkins in using I can run the cordova commands fine and everything works.
Furthermore, if I add the platform manually by sshing into the box and then let jenkins take over after the android folder already exists, the job works fine. So I guess for some reason it's not able to add the android project.
If it helps, this is what cordova requirements gives:
cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29,android-28
Gradle: installed /usr/local/Cellar/gradle/7.3.3/bin/gradle
Okay, I finally figured this SOB out! After taking a few weeks off and coming back to this I noticed that there is a setting in the job config called "Shared Workspace" and I had it set to the value (). I don't know what that means, but it had the effect of putting the code for this project in the
/Users/me/Documents/Jenkins/sharedspace
folder, which apparently was causing problems with cordova. Once I set the Shared Workspace value to NONE, it moved the project to the
/Users/trident/Documents/Jenkins/workspace/my-app
folder which is more what I would expect. After that, lo and behold, everything works.
While trying to do a release using the following command:
code-push release-cordova myApp android
I'm getting the following error in the terminal:
Running "cordova prepare" command:
[Error] Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
Any one knows what might be wrong? The project is a cordova project created using the command:
cordova create myApp
And also has android platform added.
UPDATE :
Running cordova prepare android --verbose returns the following output :
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform installed plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "io.cordova.hellocordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.
Make sure your Nodejs is the last version.
code-push-cli required "child_process"
That error indicates that the current working directory didn't represent the root of a Cordova project at the time that you ran the release-cordova command. Can you make sure that you CD into the directory that contains the www, platforms, plugins, etc. directories, and then run the release-cordova command? That should do the trick for you
I'm new to cordova mobile app development. I have install Node and then install cordova. i have done those steps to create a cordova android app.
cordova create hello com.example.hellow HelloWorld This work fine
cd hello Navigation to directory_
cordova platform add android This is not working
This is the error showing my terminal
Jeys-MacBook-Pro:hello mactec$ cordova platform add android
Creating android project...
/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:126
throw e;
^
Error: The command "android" failed. Make sure you have the latest Android SDK installed, and the "android" command (inside the tools/ folder) is added to your path.
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:85:29
at _rejected (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
at Promise.when (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
at flush (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Error: /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/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.onexit (child_process.js:810:5)
Jeys-MacBook-Pro:hello mactec$
Please help me to short-out this issue
Thanks in advance.
The problem is PATH wrongly defined on .bash_profile.
What i have done for this.
Change the path on bash profile open ~/.bash_profile. Then the bash profile open in a text editor.
Add the correct path to android SDK. If we have android studio then the path is /Application/Android Studio.app/sdk/ so we need to add this path to .bash_profile. export PATH=${PATH}:/Applications/Android\ Studio.app/sdk/tools
Then close all terminal and open again and code... :)
You can check that is working or not via typing android on terminal.
The error show in quite clear.You have to have the android sdk installed and proper path set in the system variable for the SDK, for cordova to work.See the prerequisites in cordova documentation http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html.For cordova 3.4 project android SDK must have target 19 installed.
Download SDK here http://developer.android.com/sdk/index.html
Here is the platform guide for more information http://cordova.apache.org/docs/en/3.0.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide
If you already have the SDK installed,check to see if the path is refered properly for cordova to find
There's also another potential cause for this error: an errant file in your project/www directory. I had inadvertently included a blank file called project/www/:q ("colon q") in www/ (note I use Vim)! Anyway, doing this yields the exact error as noted by JeyTheva. So, delete that file and do the following:
cordova platform remove android
rm -r ~/.cordova/lib/android
cordova platform add android
Now rebuild and run on your device. This should work if you did something similar to what I did.
I'm trying to compile my phonegap project using the cordova cli on my Win8 machine. I've updated all my Android SDKs, updated cordova and phonegap but I cannot build my project. I get an error that the .cordova/hooks/any_hook is empty.
I looked in that directory and can't see any files in there. How do those files get there and is the latest version of cordova bad? Until now I've been compiling on my Mac because I couldn't get the PC setup correctly so today I decided to take a crack at it and have failed.
I even created a new hello world project using the CLI but still no luck in building the thing because of the supposed missing hook files. Anyone have any insight to this.?
Also, I've tried using the command prompt in both ADMIN and regular mode. Still no luck.
EDIT:
I'm using phonegap 3.3.0-4.18.0
Path to hooks:
Z:\projecttitleroot\projecttitle.cordova\hooks
OUTPUT OF PHONEGAP BUILD WITH DEBUG:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[error] ENOENT, no such file or directory 'Z:\myprojectroot\myproject\.cordova\hooks\before_build'
I want to point out that I'm using phonegap command to compile and run, NOT cordova as per the documentation for the latest version.
If I run:
cordova -d build android
I get this:
Z:\myprojectroot\myproject>cordova -d build android
C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:126
throw e;
^
Error: ENOENT, no such file or directory 'Z:\myprojectroot\myproject\.cordova\hooks\before_build' at Object.fs.readdirSync (fs.js:654:18)
at C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\src\hooker.js:64:34
at _fulfilled (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:827:30)
at Promise.promise.promiseDispatch (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:760:13)
at C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:821:14
at flush (C:\Users\MYUSER\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
Z:\myprojectroot\myproject>
Make sure you put your hooks into subdirectories inside the hooks directory.
Path to hooks: Z:\projecttitleroot\projecttitle.cordova\hooks\before_build\
i am new to phonegap 3 and android development.
i tried the command "phonegap build android" and get:
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project.
fs.js:427
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory 'C:\Users\Michael\.cordova\lib\android\
cordova\3.1.0\VERSION'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at Object.exports.createProject (C:\Users\Michael\.cordova\lib\android\cordo
va\3.1.0\bin\lib\create.js:116:22)
at Object.<anonymous> (C:\Users\Michael\.cordova\lib\android\cordova\3.1.0\b
in\create:34:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
I simply add an empty file named as VERSION:
C:\Users\myuser\.cordova\lib\android\cordova\3.1.0\VERSION
after, I wrote this text inside it:
3.1.0
after, run phonegap again:
[phonegap] adding the Android platform...
[phonegap] compiling Android...
[phonegap] successfully compiled Android app
Good luck!
It is kind of tricky This is the sequence I have to go through.
run a clean in eclipse (Project Menu)
sudo phonegap build android (cordova if that is what you are using)
then you have to reapply the read write permissions to the whole folder (this step may not be needed depending on your permissions)
then in eclipse run refresh on the project
then build.
Run
I would suggest as a bare minimum first step you should check via the command line that the following commands return a response that shows they are working correctly. They are all required. Ant - http://ant.apache.org/
Java -http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-6u3-jdk-7u1-downloads-523391.html
android - http://developer.android.com/sdk/index.html
In command line type the following to validate they work
Ant
java
android
Make sure you have node.js installed (http://nodejs.org/)
Also make sure you look at you PATH file and that everything is correct there.
As I say that's the basics (once you have stuff installed)
Try to install latest cordova. Maybe it will help:
$ sudo npm install -g cordova
(also you will need node.js installed)
I have removed android platform and added again.
cordova platform rm android
cordova platform add android
then,
cordova prepare android
is done without errors