与插件科尔多瓦3.5嵌入的WebView [英] Cordova 3.5 embedded webview with plugins

查看:227
本文介绍了与插件科尔多瓦3.5嵌入的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的原生Android应用程序到我加入一个科尔多瓦web视图。 这与的Intellij新摇篮项目格式。 我已经成功地得到加载科尔多瓦活动,并打开预期。 我增加了web视图遵循科尔多瓦文档

I have an existing native Android app to which I'm adding a cordova webview. This is in the new gradle project format with Intellij. I've successfully gotten the cordova activity loaded, and opens as expected. I added the webview by following the cordova docs.

现在我想用一些可用的插件,但不能找到一种方法将它们添加到项目中。 由于这不是一个产生科尔多瓦项目,plugman不起作用。我试着复制JS和Java文件,我很感兴趣,我的源代码目录的插件,但是这会导致各种错误。

Now I'd like to use some of the plugins available but can't find a way to add them to the project. Since this isn't a cordova generated project, plugman doesn't work. I've tried copying the JS and Java files for the plugins I'm interested in to my source dir but that results in various errors.

例如。要求是不确定的,如果发生这种情况,我添加requirejs到web视图的的index.html 并转移到

e.g. require is undefined, when this happened, I added requirejs to the webview's index.html and it moved on 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 working with this?

编辑:

我手动四处移动的东西。

I am manually moving stuff around.

  1. 这必须投​​入它采用摇篮建筑现有项目。
  2. 使用科尔多瓦创建生成旧ANT格式的项目。
  3. 我也跟着在现有项目中嵌入的WebView(见上面的链接)的文档,但它并没有提及任何JavaScript文件。所以我只是复制cordova.js从Android平台目录。
  4. 像明智的,我下载我想要的插件,复制他们的JavaScript文件,添加功能到build.xml并复制它们的Java文件到我的src目录下。

我不知道cordova_plugins.js或科尔多瓦prepare产生它们。

I didn't know about cordova_plugins.js or that cordova prepare generates them.

推荐答案

您必须使用Plugman来管理你的插件内置自定义科尔多瓦web视图。

You have to use Plugman to manage your plugins in the custom built Cordova WebView.

请删除所有现有的插件,并使用plugman阅读。

Please remove all your existing plugins and read them using plugman.

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

其中&LT;凸出&GT; 是创建你的主要项目的文件夹, 另外,您可以使用--www参数,它允许你指定的Web应用程序根目录存储。例如:

where the <proj> is the folder where you main project is created, Alternatively you could use --www parameter which allows you to specify where root of web application is stored. Example:

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

Plugman参考

修改

如果您有高度定制的项目,您可以创建空的科尔多瓦项目中添加 插件,并复制 cordova_plugins.js 此项目资产\ WWW \脚本,科尔多瓦应该皮卡这些文件。如果你有你的插件JS文件不在资产\ WWW \脚本\插件\ 文件夹,而是在资产\ WWW \插件您必须修改 cordova_plugins.js 的内容一样,

If you have highly customized project, you could create empty Cordova project where you add plugins, and copy cordova_plugins.js from this project to assets\www\scripts, Cordova should pickup these files. If you have your plugins JS files not in the assets\www\scripts\plugins\ folder, but instead of that in assets\www\plugins you have to modify content of cordova_plugins.js like that

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

这篇关于与插件科尔多瓦3.5嵌入的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆