I am working on a Cordova application.
When I run the application for first time after installation, it works fine. But for subsequent runs it throws above error.
Added the cordova file transfer plugin
cordova plugin add cordova-plugin-file-transfer
Included the cordova script in my index.html
<script type="text/javascript" src="cordova.js"></script>
Using the app directory as below
alert(cordova.file.applicationDirectory);
Above line alerts or prints the path correctly when I run my application for the first time, soon after installation. But in the next runs I get the error "Cannot read property 'applicationDirectory' of undefined".
ANSWER IN BELOW COMMENTS
My issue fixed when I used the "file:///android_asset/www/Images/" instead of cordova.file.applicationDirectory+"/Images"
Related
I have a VueJS project with a "fakeDB.js" file that drives the database via local storage (browser) during development. After testing this locally, everything is working and I can navigate to pages perfectly fine.
I'm now running npm run build to get the js/css files to place into a Cordova application for an Android application. After copying these files into the application and switching the VueJS application to use the SQLITE3 inside Cordova I experience issues.
My login pages work perfectly fine, I can view the dashboard with all the jobs inside it but if I click into a job it throws a white screen.
After hooking up adb debug, all I can see is an error in the chunk-vendor file that npm run build created which, AFAIK, contains the vendor packaging.
The error message I get is:
"TypeError: Cannot read property 'substr' of undefined", source: file:///android_asset/www/js/chunk-vendors.f024a0c1.js (7)
Of course, this file is obfuscated and minified so Line 7 is VueJS 2.6.12.
I have inherited this application with no previous experience so I'm taking an educated guess around "chunk-vendor" that I perhaps need to upgrade the depedencies surrounding this application to get past this issue but I'm unsure how I can debug this further inside of android studio.
How can I go about solving this issue? Is there a way to upgrade safely inside of npm?
Update: I have ran a npm update and I'm now on VueJS 2.7.10 but still getting the same issue
I am building a project with Cordova for iOS and Android platforms (cordova version 7.0.1 and platform iOS 4.5.1 and platform android 6.2.3). When I use the command cordova run ios or cordova run android I find that the iOS build will somehow not have embedded cordova.js and although the pages will load, none of my cordova plugins will work and the debugger shows the following error:
exception nativeEvalAndFetch : ReferenceError: Can't find variable: cordova
If I manually include <script type="text/javascript" src="cordova.js"></script> in my index.html file and run the command again, everything works fine (although then android complains of a second declaration of cordova.js)
I would like to have one build where I don't have to constantly modify one or the other environment. Here are some other things I have noticed when running those commands:
I have verified that the index.html and three js files (app, manifest and vendor) are identical between their iOS and Android generated versions (in /platforms/ios/www and /platforms/android/assets/www respectively).
Also the other files present in each folder seem to match.
Because the appropriate files seem to match, I believe this bug is at the point where the command loads the bundle/app onto my iPhone or simulator, and as I said plugins will not work without force including it in the index.html file, but everything outside of plugins works fine in the app.
I seem to be having an issue with all Cordova plugins that I am adding to my project. For this question, I will reference specifically the SplashScreen plugin.
The process that I take when building my project for IOS is as follows:
ionic cordova platform add ios
ionoc cordova prepare ios
ionic cordova build ios
At this point, the build will fail with an error 65 on xcode args. After some googling, I found that a solution to this is to perform ionic cordova platform update ios, this fixes the problem and allows me to compile and run my application, yay!
The reason that I have included the above details is, I am worried that perhaps updating the platform is for some reason causing the plugins not to load / be included. Just a thought but thought I would include that process for reference.
When running my project in the IOS emulator on mac, I get the following plugin errors in the console for xCode, this error message is specifically for the StatusBar but is the same for all other plugins I have added:
2017-08-13 20:41:36.391 Shokuni[20906:1123728] CDVPlugin class CDVStatusBar (pluginName: statusbar) does not exist.
The plugins then reset due to page load…
2017-08-13 20:41:37.724 Shokuni[20906:1123728] Resetting plugins due to page load.
Then i get the following error about the status bar, which I assume is because it is being attempted to be used on the first page loaded in the project
2017-08-13 20:41:38.883 Shokuni[20906:1123728] CDVPlugin class CDVStatusBar (pluginName: StatusBar) does not exist.
2017-08-13 20:41:38.883 Shokuni[20906:1123728] ERROR: Plugin 'StatusBar' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
Inside xCode, in the File Explorer panel on the left, there are no plugins inside the plugin folder, I am wondering whether this could potentially be an issue? I can however see that the plugins that I have installed are available at staging/www/plugins
Anybody had this problem before or knows about what may be going on? If so I would be very grateful.
How I can add plugins in my Cordova app? I can't find any examples. I'm trying to install and add plugins in nodejs prompt: npm i PLUGIN_NAME and cordova plugin add PLUGIN_NAME. After that, I'm trying to write a code for this plugin in my index.html file in tag <script></script> and I have many errors in console like that: Uncaught ReferenceError: cordova is not defined(…) or another. I did read many documentation about that and I know that I need to add any records about plugins to config.xml file. But how I can do it? Can you help me with this trouble?
To add plugin, use the following command:
cordova plugin add PLUGIN_NAME
Once the plugin is added, to invoke the plugin code, register deviceready event in your code and invoke the plugin code inside the device ready event listener. Also ensure to include cordova.js file in your HTML which will give 404 error on development but will included once you build your android or browser platform and it will be available during the execution.
Check out this SO Post for more info on this. You can also check out this sample cordova app which uses local notification plugin as a reference for plugin invocation
You need to add reference to cordova.js in your index.html file like following,
<script type="text/javascript" src="cordova.js"></script>
This can appear in head section or at bottom in body section. But refer it before any other js references.
I've been trying everything for the past two days to solve this issue. I'm well and truly stumped. Perhaps someone with greater knowledge than I can shed some light on the issue:
Basically, I'm building an app in AngularJS with the purpose of building Android and iOS apps from it using Cordova. I should specify that I am using cordova-cli on Linux and ngCordova (wrapper around plugins). I am NOT using Ionic Framework.
My app works fine in Chrome. I followed the ngCordova installation guide perfectly: http://ngcordova.com/docs/install/
I used bower to install. Then included the following in the index.html of my Web App project (not the Cordova project):
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
It didn't work. I thought maybe it's because the ng-cordova.js went into my bower components directory. So I changed that script tag to:
bower_components/ngCordova/dist/ng-cordova.js
When I go to my cordova project directory and set up the platforms, plugins etc... and run:
cordova build android
followed by
cordova run android
The app runs on my device (Nexus 5). I use chrome://inspect to see what happens when I click the button which should be using the email composer plugin: I get a cordova not defined error.
I went into the controller and put this in
console.log($cordovaEmailComposer);
I can examine this in chrome://insepct and it has all the correct functions etc.. so ng-cordova.js is running fine (thats where the factory for the plugin is).
I'm 99% sure the issue is that somewhere along the line cordova.js is being lost. When I go into the cordova project in the ProjectName/www/index.html the tag for cordova.js is commented out.
Same in the platforms/android/assets/www/index.html file.
I traced it back and the same is true in WebAppProject/dist/index.html file. It's commented out. So it seems that when I run grunt build cordova.js is being removed. I thought maybe it's because cordova.js wasn't in the WebAppProject so I brought it into the root directory (same locations as index.html) and it still happened.
Can anyone explain how to properly get this working? I'm totally at a loss. I've tried a million different ways of including cordova.js. I even manually uncommented it out in the cordovaproject/www/index.html. The app builds but crashs upon opening (white screen then dies) suggesting a missing script (despite cordova.js being n that directory too...).
Is this the grunt build process? Or am I totally setting up an ngCordova project incorrectly without realising... I would post some code but I'm 99% sure the issue is with cordova.js or the way the project is building upon either grunt build or cordova build.
Any help would be much appreciated. :)
Cheers,
D
Make sure to include ngCordova before cordova.js and after angular.js.
<script src="/path/to/angular.js"></script>
<script src="/path/to/ng-cordova.js"></script>
<script src="/path/to/cordova.js"></script>