missing cordova_plugins.js Failed to load resource

  • 2
  • Question
  • Updated 4 years ago
file:///android_asset/www/cordova_plugins.js Failed to load resource: net::ERR_FILE_NOT_FOUND

I have researched this and it seems from everything I have read it something on your end, I am referencing cordova.js not phonegap.js and I am still experiencing this issue.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 2
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Could you please confirm:
- that you are building with Phonegap Build. No local build.
- that your config.xml and index.html are both in the root directory of your zip file
- that you reference cordova.js this way:
<script src="cordova.js"/>
- that the error occurs in the index.html, not in a different html document inside a subdirectory
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
Yes I am referencing in that manner, I managed too figure out the problem I forgot to reference plugins, although now I am receiving the error,

Uncaught TypeError: Cannot read property 'getCurrentAcceleration' of undefined
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Are you waiting for the deviceready event to fire before invoking that method?
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
yes I tried two different syntax's, with this syntax my device does nothing but I get no error

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
startWatch();
}

with this I get the error

document.addEventListener("deviceready", onDeviceReady(), false);
function onDeviceReady() {
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
startWatch();
}
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Of course. The latter is wrong. You can't call the callback function yourself...it must be done by the eventlistener.

In the former syntax, how do you define the success callback?
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
as such

function onSuccess(acceleration) {
var accelerationChange = {};
if (previousAcceleration.x == null && previousAcceleration.y == null && previousAcceleration.z == null) {
previousAcceleration.x = acceleration.x;
previousAcceleration.y = acceleration.y;
previousAcceleration.z = acceleration.z;
} else {
var accelerationDelta = {
x: acceleration.x - previousAcceleration.x,
y: acceleration.y - previousAcceleration.y,
z: acceleration.z - previousAcceleration.z
}
var maginitude = Math.sqrt(
Math.pow(accelerationDelta.x, 2) +
Math.pow(accelerationDelta.y, 2) +
Math.pow(accelerationDelta.z, 2)
);

if (maginitude >= 12) {
rollDice();
stopWatch();
setTimeout(startWatch, 1000);
previousAcceleration = {
x: null,
y: null,
z: null
}
} else {
previousAcceleration = {
x: acceleration.x,
y: acceleration.y,
z: acceleration.z
}
}
}
}
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
If it's easier here is a pastebin of the whole file,

http://pastebin.com/MuP9u7iC
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Does your code execution actually reach the line
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);

If so, what are the object type values for navigator.accelerometer and for navigator.accelerometer.getCurrentAcceleration?
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
The code never hits that line
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, the deviceready event never fires.
I could ask 20 more questions now, but it would be better to see your project. Is your zip file available online somewhere? If so, please post its url and I'll be happy to have a look.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
The weird thing about this is I managed to get the application to work with Ripple emulator.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Ah, there we are. Your config is all wrong.

<access origin="*"/>
This will do nothing without the whitelist plugin from npm, unless you are building with PGB3.x (which you are, but you shouldn't; use at least cli-5.2.0)

<gap:plugin version="0.2.12" name="org.apache.cordova.device" source="pgb"/>
That's an ancient plugin version. Use the latest plugin from npm. Be aware that it is named differently (cordova-plugin-device).

<gap:plugin version="0.5.2" name="org.apache.cordova.inappbrowser" source="pgb"/>
That's an ancient plugin version. Use the latest plugin from npm. Be aware that it is named differently

<gap:plugin name="cordova-plugin-device-motion" source="pgb" spec="1.1.1"/>
That plugin doesn't exist at pgb.. Use the latest plugin from npm.

<!-- Use the newest version of PhoneGap -->
<preference name="phonegap-version" value="3.6.3"/>

Yeah, right. 3.6.3 is almost two years old. You can't use that anymore.

<!-- Device permission is needed -->
<feature name="http://api.phonegap.com/1.0/device"/>

Feature elements are obsolete. Also, you don't need it if you have a proper device plugin referenced.

Note: your config is lacking icons and splashes. For Android: strongly recommended, for iOS (which you aren't building now) required.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
Thank-you very much for your help, I am very new to this, I actually ended up making my own splash page cause I wanted to use an animated gif, not sure if this is frowned upon though.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
So now my code works on the first dice roll, but afterwards it does nothing.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
It just loops in this block of code inside of accelerometer.js,

timers[id] = {
timer: window.setInterval(function () {
if (accel) {
successCallback(accel);
}
}, frequency),
listeners: p
};
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
inside of accelerometer.js
I can't find such file in your zip package.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
thats a package pulled from node package manager
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
its part of cordova-plugin-device-motion
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
its triggered by the navigator.accelerometer.watchAcceleration(onSuccess, onError, options); function it seems the accelerometers stop working after the first call.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I'm totally lost.
Why are you doing that? You should simply use the documented api functions from the plugin's docs. The internals of the plugin should be an uninteresting black box to you.

Just start navigator.accelerometer.watchAcceleration (with the options parameters as desired) and act upon the results in the success callback function.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
thats what I am doing
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
I can see the externals of the plugin with chromes browser though
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
my debuger gets stuck in the plugin and the success function won't fire, it works in an emulator though.
Photo of Jamie Steele

Jamie Steele

  • 27 Posts
  • 0 Reply Likes
this is my start watch function

function startWatch() {
watchId = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}

the code gets here and then never hits the success function except for the first time.