0

I've got a problem concerning cordova. This is a simple topic about the installation of cordova, the creation of a project and the addition of plugins. Actually I thought that everything was ok until I try to add plugins in my project. The methods associated with the cordova plugins are not recognized at the execution of the program... I express myself:

I've correctly installed nodeJS, correctly set the environment variables etc... Then I install cordova by typing: npm install -g cordova Everything's ok at this moment.

After that, I try to create a new project: cordova create Test com.example.test Test for example For now, compared to the tutorial video here at 9:37, I have:

Creating a new cordova project with name "Test" and id "com.example.text"
at location [...]"

But I don't have the to last lines of the video:

Downloading cordova library for www...
Downloading complete

So there's already something weird here...

I specify an android project by typing:

cordova platforms add android

And after that, the terminal display the following lines:

Creating android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.example.test
        Name: test
        Android target: android-19
Copying template files...
Project successfully created

but it seems that in the same video as before at 10:27, a lot of things should happen that it doesn't seem to happen to me...

The project is nevertheless "correctly" created, despite of these elements BUT: the libs folder is empty (and I think this is the problem...)

Ok, after that I try to add a plugin, I type: cordova plugin add org.apache.cordova.device-orientation to get the compass plugin.

The AndroidManifest.xml and res\xml\config.xml are correctly modified to set the features (in build.xml) and the permissions (in AndroidManifest.xml), then I don't think this is here my problem...

But for a trivial code like:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes.     See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>

        <script>
            if(navigator.compass)
                alert("ok");
            else
                alert("not supported");
        </script>
    </body>
</html>

I've got an alert saying "not supported" (navigator.compass is undefined)

It seems that this problem persists for the other plugins of cordova; I can't use their associated method... except for one: navigator.geolocation; I don't know why but this is the only thing that is recognized when I use it.

Well, I don't know what to do, I've seen some other topics on "jar file missing" especially this one but I'm not sure this is the real problem. But if it is I don't understand where to place the generated jar file in the project...(??)

Anyway, if you have ever faced this kind of situation, I really would appreciate because it makes 3 complete days now that I try to fix this problem.

Note: This is maybe not necessary to say it but I try to entirely code my project in javascript (to produce an application applicable on many platforms not only android [here it is just to test]). If there are permissions to add or some little things like that it's ok, but I prefer to limit the android specifications.

Waiting for your answers, thank you for all

Community
  • 1
  • 1
Gaétan Séchaud
  • 219
  • 1
  • 3
  • 14

2 Answers2

0

Got the same sort of problem here,

I managed to install cordova and all of it. But my build.phonegap says it does not contain any plugins. Also when i try to type navigator.c to get navigator.camera. There is no camera option to be showed.

None of my plugins work.

And i've got a ondeviceready function what does not work either.

document.addEventListener('deviceready', test, false);
function test() {
    alert('hi');
}

No hi message popsup on my android phone when i downloaded, installed and opened my app.

Mart
  • 475
  • 4
  • 21
  • This is not really the same sort of problem. If I write your code in mine, it works perfectly. Then for me it is just a problem for the cordova plugins. Maybe your problem here is that your version is too old; try to reinstall cordova with a highest version (maybe :)) – Gaétan Séchaud Oct 21 '14 at 20:40
0

I guess it is because your are using too early your plugin. You can use only the plugin code when the device is ready since the js is dynamically loaded.

If you do something like that, it should work:

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

function onDeviceReady() {  
  if(navigator.compass)
           alert("ok");
     else
          alert("not supported...");       
}
nicolas
  • 489
  • 1
  • 3
  • 22