Cordova 3.5 embedded webview with plugins

I have my own android app to which I add cordova webview. This is in the new gradle project format with Intellij. I loaded the cordora activity successfully and responded as expected. I added webview following the line docs .

Now I would like to use some of the available plugins, but cannot find a way to add them to the project. Since this is not a generated cord project, plugins do not work. I've tried copying the JS and Java files for the plugins I'm interested in to the original directory, but this results in various errors.

eg. require undefined, when it happened i added requirejs to webview index.html and it went to

Uncaught Error: Module name "cordova/exec" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded cordova.js:8
Failed to load resource file:///android_asset/www/scripts/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1191
Channel not fired: onDOMContentLoaded 

      

How do I get a plugin that works with this?

EDIT:

I am manually moving things around.

  • This needs to be included in an existing project that uses gradle to build.
  • Using cordova create creates the project in the old ANT format.
  • I followed the docs on embedding a WebView in an existing project (see link above) but it doesn't mention any of the JavaScript files. So I just copied cordova.js from the android platform directory.
  • As wise, I download the plugins I wanted, copied their JavaScript files, added this function to build.xml and copied their Java files to my src directory.

I didn't know about cordova_plugins.js or what cordova prep generates.

+3


source to share


2 answers


You must use Plugman to manage your plugins in a custom Cordova WebView.

Remove all existing plugins and read them using the plugin.

plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts

      



where <proj>

is the folder where you create the main project.Alternatively, you can use the --www option, which allows you to specify where the web application root is stored. Example:

plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts

      



Plugin link

EDIT

If you have a highly customizable project, you can create an empty Cordova project where you add plugins and copy cordova_plugins.js

from that project to assets\www\scripts

, Cordova should pick up these files. If you have plugin JS files not in folder assets\www\scripts\plugins\

but instead in assets\www\plugins

you need to change content cordova_plugins.js

like this

module.exports = [
.....
{
    "file": "../plugins/org.apache.cordova.inappbrowser/www/InAppBrowser.js",
    "id": "org.apache.cordova.inappbrowser.InAppBrowser",
    "clobbers": [
        "window.open"
    ]
},
...
]

      

+1


source


Here is some data on how I arrived, I am in a similar position like the OP, implementing Cordova webview in my android app. After doing plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts

What Happens, you get a new Cordova folder in the original "main" folder (where your AndroidManifest.xml is located). In addition, there is a 'src' folder with the code you really need.



What I did was copy the org folder from src to the "java" folder. And it all worked.

0


source







All Articles