I ran into a similar problem in which I need to download PhoneGap files and dependent plugin files based on platform type. I went through the PhoneGap source and found that it uses windows / browser events to load and prepare objects. If I manually trigger browser events, it initializes the PhoneGap objects (APIs and plugins) that I need to run my application.
The following code that uses Yabble now worked for me:
<html>
<head>
<script
src="https://raw.github.com/jbrantly/yabble/master/lib/yabble.js"></script>
<script>
require.setModuleRoot("js");
require.useScriptTags();
require.ensure([ "jquery", "phonegap" ], function(require) {
PhoneGap.onPhoneGapInit.fire();
require.ensure([ "plugin1" ], function() {
$("#console").append("Plugin1 loaded<br>");
});
$("#checkDevice").click(function() {
console.log(JSON.stringify(device));
});
$("#callPlugin").click(function() {
window.plugins.plugin1.call();
});
});
</script>
</head>
<body>
<div id="console"></div>
<input type="button" id="checkDevice" value="Check Device">
<input type="button" id="callPlugin" value="Call Plugin">
</body>
</html>
Both device information and the plugin work fine on Android. Although I have not tested all the PhoneGap APIs, at the moment I only need these two to work, and they work.
Edit
Phonegap 1.5/Cordova, PhoneGap.onPhoneGapInit.fire(); - API. - JS . - Lazy Load Test