I have a problem in my vuejs + cordova project, when there is an edit file for example (login.vue) the changes only appear when running the 'npm run serve' command but when running the command 'cordova run browser / android' the login.vue file is not updated. I've tried clear cache 'npm clear cache' and 'cordova clean / cordova prepare' the results are still the same.
Command Before run/build cordova :
npm run serve
npm run build
cd cordova_app
cordova run/build android or browser
it is because the latest changes you made to files need to be brought to the platform folder (E.g. $projectroot/platform/android/www).
For this you have two options:
you can edit the file here directly
$projectroot/platform/$platform_name/www, but as a result, if you delete the platform, then that change will get lost.
Or you can make also make the changes in $projectroot/www/ but you will need to run few commands: cordova platform remove android and cordova platform add android if it is for Android. Please note that this will also overwrite any special configuration you have made in your IDE (xCode for iOS or Android Studio for Android) because it regenerates from your code, a new workspace for your app to be compiled, including your latest code, all in the platform folder.
Good luck!
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.
I'm working on a Cordova plugin. As a plugin can't be executed, I'm using a Cordova project to test it. I found that running a Cordova project will not reimport and rebuild plugins, so currently I'm doing this:
rmdir \"./plugins/my-plugin\" /q /s
cordova platform remove android
cordova platform add android
cordova run android --device
Did I miss something or Cordova really doesn't have a command to fully rebuild everything before running the project?
Unfortunately, cordova will check your plugins folder only when adding or updating a plugin or platform. Then it will build and copy the needed plugin(s) into the designated OS in the platforms folder.
By your script I assume the source of the plugin is outside of the project folder. So the script you're using should do the work. But if I may give you a better solution would be as follows:
Create a Symlink/shortcut of the source folder for your plugin into the plugins folder, so you'll not need to remove the folder and stress the disk into copying files everytime you want to run the update.
Your "update" script should delete only the installed plugin folder at platforms/android/platform_www/plugins/my-plugin and it'll make the update far more quickier than removing and adding the platform again.
I've created a Vue project and add a cordova plugin, like this:
vue create app-test
vue add cordova
npm run cordova-serve-android
Everything works up to this point.
Then I've tried to do this:
vue add vuetify
When I run:
npm run cordova-serve-browser
Everything fine, but when I run
npm run cordova-serve-android
Just a blank screen was rendered
Examining the code with the debugger, there's no App.vue, nor HelloWorld.vue instantiated.
I've just find a lot of errors on console:
Failed to load resource: net::ERR_CONNECTION_REFUSED
https://localhost:8080/sockjs-node/info?t=1570409595173
Please suggest.
How It worked for me (without using vue cordova plugin)
Remove and install new version nodejs and cordova
Created a cordova project and added platform android (don't build or run android from the command prompt.. it will create lot of errors)
Then open the created android project (\platforms\android) in android studio (use the latest version of android studio),on open it will ask for gradle upgrade, then "Ok" to update the build gradle and wait for the update finish.
then run the project from android studio,
if the cordova hellworld project is working, then replace the content of 'platforms\android\app\src\main\assets\www\' with the content in 'dist' folder created by using the vuejs build command.
Then run the project from the android again, Now you can view your app
(optional) if you are sending non https requests from the app, then android:usesCleartextTraffic="true" in the AndroidManifest.xml file
Note : You have to build the vuetify project every time to generate 'dist' folder and need replace the files in www folder
I am trying to check for an established network connection through the phonegap/cordova API, but alas, it is not working.
I added the plugin as explained on the cordova documentation, and phonegap local plugin list gives [phonegap] org.apache.cordova.network-information.
However, simply calling
document.addEventListener("deviceready", function () {
alert(Object.keys(navigator.connection));
}, false);
results on my phone (Android 4.0.4) always returning 0 and running on an emulator with Android 4.4.2 logs into LogCat that navigator.connection is undefined. In fact, on both machines alert(Object.keys(navigator)); never shows the connection key.
Any solution?
Phonegap with Cordova 3.3.0
When you install the plugin it copies files to www/plugins and updates android.json
then when you build the project, the build copies the java to platforms/android/src/... and the js files to platforms\android\assets\www\plugins (and does any customisation defined in plugin.xml)
At multiple occasions I saw android.json not correctly updated and javascript files not copied. Removing and re-installing plugins solved the problem for me.
If you did not perform manual customisations to the platforms/android folder, I think the easiest way to clean your project would be to empty the /plugins folder and the platforms folder and then re-install all the plugins you need.
I had the same issue and found I had to run "cordova build" and then the status was returned correctly.
BEWARE
When I run cordova build, it appears to take everything in my ~/app/www directory and overried everything in app/platforms/android/assets/www/
My "install process" is as follows:
cordova create app com.app "App"
cd app
cordova platform add android
cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.geolocation
cordova build
I can then do code changes in app/www and when happy, 'deploy' it using 'cordova build' (which seems to always copy the files to app/platforms/android/assets/www/.
If I add another plugin using: (for example)
cordova plugin add org.apache.cordova.file
then I need to run
cordova build
to have it work.
I hope this helps
(I am using cordova 3.3.1-0.1.2 )
I have created the project with cordova CLI but i do not know where i need to change and how to run the cordova android project with eclipse for each platform. Thanks for helping
Before run the android project inside your Cordova Project you should know these things.
If you are making any changes in the Cordova Project then first you need to prepare the cordova. use the command cordova prepare
Then it changed in your config.xml (for android) automatic as you added or any changes you made. Do not make any change in your android project which exist inside your Cordova project. You can only make change inside the www folder of your Cordova project. And after made changed you need to make cordova prepare every time.
After prepare the cordova you can run the android project on device or emulator. For this you make sure you have made the path of android sdk for platforms-tools and tools in your environment system. If you not configure this path and add this two path in system environment .
Now run the android project on device use command cordova run android and run on emulator use this command cordova emulate android.
And if want to run on eclipse then you should import this android project of your workspace in eclipse. But if you again made changes in your cordova project then need to delete and again import the android project this switching happened every time so better to run through CLI.
I hope you got all things
Sunil's answer is good. I would like to add logging using Android Debug Bridge(adb).You may want to run:
adb logcat on a seperate shell window for logs after running cordova run android you need when you run into errors.This will produce huge logs, so I would recommend using:
adb logcat|grep Cordova