Cordova 3.0 just using device plugin error

cordovahybrid-mobile-app

I'm using Cordova 3.0. I'm able to create a skeleton project and run it without any problem. Now I want to add the Device plugin. Here are my steps:
1. Added assets\www\device.js
2. Modified res\xml\config.xml and added:

<feature name="Device">
    <param name="android-package" value="org.apache.cordova.Device" />
</feature>
  1. Modified AndroidManifest.xml and added:
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  1. Added src\Device.java

  2. In index.html I added script src:

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

In the index.js I added the following code:

onDeviceReady: function() {
    app.receivedEvent('deviceready');
    console.log('device.model=>' + device.model);
},

I build and run on the android emulator and get the error:

10-03 12:22:49.998: E/Web Console(637): Uncaught ReferenceError: require is not defined at file:///android_asset/www/device.js:22

10-03 12:22:50.489: I/Web Console(637): device.model=>undefined at file:///android_asset/www/js/index.js:40

Any ideas on what im missing? I've followed the instructions at the phonegap site
http://docs.phonegap.com/en/edge/cordova_device_device.md.html#Device

Best Answer

You should use the official method to install the plugin. Run

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

from your command line and it should take care of all the modifications for you. You should remove all of your modifications first.

Related Topic