title: "plugins is not defined" in PhoneGap Application
body: <p>I am currently trying to use the <strong>PhoneGap LocalNotification Plugin</strong>, 
  using Android 4.1 together with Cordova 2.0.0 and Sketcha (UI Library).</p>
  
  <p><strong>UPDATE #2 20/9/12: I've used Bozzzi's code with some fixes:</strong> </p>
  
  <ol>
  <li>Added }) to the end of localnotification.js (syntax error).</li>
  <li><p>changed <code>cordova.define("cordova/plugin/LocalNotification", function(require, exports, module)</code> to:
  <code>cordova.define("cordova/plugin/LocalNotification", function(require, exports, module)</code>,
  so the modules name will match for this function (before the module wasn't found):</p>
  
  <blockquote>
    <p>window.plugins.LocalNotification =
    cordova.require("cordova/plugin/LocalNotification");</p>
  </blockquote></li>
  <li><p>change from this:</p>
  
  <blockquote>
    <p>if (!window.plugins) {
            window.plugins = {};
        }
        else if (!window.plugins.LocalNotification) {
            window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
        }</p>
  </blockquote></li>
  </ol>
  
  <p>to this:</p>
  
  <pre><code>if (!window.plugins) {
      window.plugins = {};
  }
  
  if (!window.plugins.LocalNotification) {
      window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
  }
  </code></pre>
  
  <p>before this change, if window.plugins is not found, it will be created but the window.plugins.LocalNotification wouldn't.</p>
  
  <p>After all these fixes I am getting this error:</p>
  
  <blockquote>
  <pre><code>&gt; 09-20 01:22:27.355: D/CordovaLog(8297):
  &gt; file:///android_asset/www/index.html: Line 21 : PAPA AMERICANO ready
  &gt; 09-20 01:22:27.360: I/Web Console(8297): PAPA AMERICANO ready at
  &gt; file:///android_asset/www/index.html:21 09-20 01:22:27.370:
  &gt; D/CordovaLog(8297): Uncaught TypeError: Cannot call method 'add' of
  &gt; undefined 09-20 01:22:27.375: D/CordovaLog(8297):
  &gt; file:///android_asset/www/index.html: Line 35 : Uncaught TypeError:
  &gt; Cannot call method 'add' of undefined 09-20 01:22:27.375: E/Web
  &gt; Console(8297): Uncaught TypeError: Cannot call method 'add' of
  &gt; undefined at file:///android_asset/www/index.html:35 09-20
  &gt; 01:22:29.185: D/DroidGap(8297): onMessage(spinner,stop) 09-20
  &gt; 01:22:30.255: E/SKIA(8297): FimgApiStretch:stretch failed 09-20
  &gt; 01:22:41.755: E/SKIA(8297): FimgApiStretch:stretch failed 09-20
  &gt; 01:22:52.565: D/CordovaWebView(8297): &gt;&gt;&gt; loadUrlNow() 09-20
  &gt; 01:22:52.565: D/webkit(8297): Firewall not null 09-20 01:22:52.565:
  &gt; D/webkit(8297): euler: isUrlBlocked = false
  </code></pre>
  </blockquote>
  
  <p>For some reason the <code>cordova.require("cordova/plugin/LocalNotification")</code> dont set the <code>window.plugins.LocalNotification</code> value and it keeps being undefined.
  Here is my updated index.html (Update #2):</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html manifest="" lang="en-US"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;AndroidSencha&lt;/title&gt;
      &lt;script id="microloader" type="text/javascript" src="cordova-2.0.0.js"&gt;&lt;/script&gt;
      &lt;script id="microloader" type="text/javascript" src="LocalNotification.js"&gt;&lt;/script&gt;
      &lt;script id="microloader" type="text/javascript"&gt;
  
      function onDeviceReady() {
          if (!window.plugins) {
              window.plugins = {};
          } else if (!window.plugins.LocalNotification) {
              window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
          }
      }
  
      window.document.addEventListener("deviceready", appReady, false);
  
      function appReady() {
          console.log("PAPA AMERICANO ready");
  
          var d = new Date();
          d = d.getTime() + 2 * 1000; //60 seconds from now
          d = new Date(d);
  
          if (!window.plugins) {
              window.plugins = {};
          }
  
          if (!window.plugins.LocalNotification) {
              window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
          }
  
          window.plugins.localNotification.add({
              date: d,
              message: 'This is an Android alarm using the statusbar',
              id: 123
          });
      }
  
      &lt;/script&gt;
      &lt;style type="text/css"&gt;
           /**
           * Example of an initial loading indicator.
           * It is recommended to keep this as minimal as possible to provide instant feedback
           * while other resources are still being loaded for the first time
           */
          html, body {
              height: 100%;
              background-color: #1985D0
          }
  
      &lt;/style&gt;
  
      &lt;!-- The line below must be kept intact for Sencha Command to build your application --&gt;
      &lt;script id="microloader" type="text/javascript" src="sdk/microloader/development.js"&gt;&lt;/script&gt;
          &lt;style type="text/css"&gt;
  .loadingText{
  color: white;
  font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
  text-align: center;
  font-size: 20px;
  padding-top: 10%;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="appLoadingIndicator"&gt;
      &lt;div class="loadingText"&gt;&lt;div style="margin-bottom: 10px;"&gt;Loading, Please wait..&lt;/div&gt;
      &lt;div&gt;&lt;img src="resources\images\smileloading.gif"&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my localnotificaiton.js after my fixes (Update #2):</p>
  
  <pre><code>cordova.define("cordova/plugin/LocalNotification", function(require, exports, module) {      
  
  var exec = require("cordova/exec");
  var LocalNotification = function () {};
  
  LocalNotification.prototype.add = function(options) {
              var defaults = {
                  date : new Date(),
                  message : '',
                  ticker : '',
                  repeatDaily : false,
                  id : ""
              };
          if (options.date) {
                  options.date = (options.date.getMonth()) + "/" + (options.date.getDate()) + "/"
                          + (options.date.getFullYear()) + "/" + (options.date.getHours()) + "/"
                          + (options.date.getMinutes());
              }
  
              for ( var key in defaults) {
                  if (typeof options[key] !== "undefined")
                      defaults[key] = options[key];
              }
  
              cordova.exec(null, null, "LocalNotification", "add",  new Array(defaults));
  };
  
  LocalNotification.prototype.cancel = function(notificationId) {
      cordova.exec(null, null, 'LocalNotification', 'cancel', new Array({
          id : notificationId
      }));
  };
  
  LocalNotification.prototype.cancelAll = function() {
      cordova.exec(null, null, 'LocalNotification', 'cancelAll', new Array());
  };
  
  
  var LocalNotification = new LocalNotification();
  module.exports = LocalNotification
  });
  </code></pre>
  
  <p><strong>UPDATE #1:</strong> I've already added the plugin to the plugins.xml file:</p>
  
  <pre><code>&lt;plugins&gt;
  ...
    &lt;plugin name="LocalNotification" value="com.phonegap.plugin.localnotification.LocalNotification"/&gt;
  ...
  &lt;/plugins&gt;
  </code></pre>
  
  <p>I've done the steps mentioned <a href="https://github.com/phonegap/phonegap-plugins/tree/master/Android/LocalNotification" rel="nofollow noreferrer">here</a> and replaced the broken java expressions as mentioned <a href="http://simonmacdonald.blogspot.co.il/2012/07/phonegap-android-plugins-sometimes-we.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Unfortunately, when I run the application I get the following error (Both in emulator and device):</p>
  
  <blockquote>
    <p>09-16 16:46:16.330: E/Web Console(27875): Uncaught ReferenceError:
    plugins is not defined at file:///android_asset/www/index.html:74</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/10218745/trying-to-get-the-android-localnotification-plugins-for-phonegap-to-work-in-cord">This guy was facing the same problem</a> but I've referenced the cordova javascript file in my index.html and its still not working.</p>
  
  <p>This is how my package explorer looks like (You might find something missing):
  <em>I am not sure if I should have plugins.xml or have config.xml and have the plugins in it,
  I have both just in case</em></p>
  
  <p><img src="https://i.stack.imgur.com/PEQsZ.png" alt="Package Explorer"></p>
  
  <p>Thanks in advance!</p>