window.phonegap is undefined after successful phonegap build

This is my first time building something with phonegap, angularjs, ionic, yeoman and grunt. The app works great for web, but I'm trying to build it through phonegap. The steps I take are:

$sudo grunt build

This builds everything fine, and the response is:

Done, without errors.

Execution Time (2014-09-14 19:07:13 UTC)
concurrent:dist    3m 31.6s  _________________________________ 35%
autoprefixer:dist   2m 9.1s  ____________________ 22%
concat:generated   2m 26.4s  _______________________ 24%
ngmin:dist         1m 24.3s  _____________ 14%
cdnify:dist             14s  ___ 2%
uglify:generated       8.8s  __ 1%
Total 10m 0.4s

Next, I run:

$ phonegap remote build android

[phonegap] compressing the app...
[phonegap] uploading the app...
[phonegap] building the app...
[phonegap] Android build complete

From there i download the .apk and open it on my android phone.

The problem is that phonegap is not initialized somewhere, and the window.phonegapis undefined.

Here is the code for watching for window.phonegap in app.js:

var PhoneGapInit = function () {
  this.boot = function () {
    angular.bootstrap(document, ['mobileAppApp']);
  };
  if (window.phonegap !== undefined) {
    document.addEventListener('deviceready', function() {
     this.boot();
    });
  } else {
    alert('PhoneGap not found, booting Angular manually');
    this.boot();
  }
};

angular.element(document).ready(function() {
  new PhoneGapInit();
});

In index.html, I have it initialized so far as I know with

<!-- build:js(.) scripts/vendor.js -->
<script src="phonegap.js"></script>

What vital piece of info am I missing? I can include the corresponding config.xml and Gruntfile.js if asked. Thanks in advance!

I ran into a similar issue today. There were a two issues in my project.

1) First of all: I had to move the phonegap.js outside the <!-- build:js(.) scripts/vendor.js --> block, otherwise the grunt build task would concatenate all those files and replace it with a reference to vendor.js. But the phonegap.js will only be added during the Phonegap build process, but then there won't be any references in your HTML.

2) You are probably building against a recent (> 3.0) version of phonegap. The scope was renamed to cordova. Change your code to

if (window.cordova !== undefined) {
document.addEventListener('deviceready', function() {
 this.boot();
});

3) OPTIONAL: You could change the reference from phonegap.js to cordova.js. PhoneGap Build inserts to files (phonegap.js and cordova.js), while phonegap.js could be considered deprecated and might be removed in a future version, but both files contain the same code.

This solved the issue for me.