Cordova项目添加Android本机模块 [英] Cordova Project add Android Native Module
问题描述
我创建了一个Cordova应用程序,并将一个Native模块添加到Android项目中。
我已经将该模块的依赖项添加到了项目中,并且如果一切正常,我使用android studio构建。
但是,当我执行命令 cordova build android时,文件settings.gradle会自动生成为默认设置,如下所示:
//生成的文件-不要编辑
包括:
包括:CordovaLib
因此,即使无法在 settings.gradle中定义模块 mymodule,构建也始终会失败。 p>
我试图找到生成settings.graddle文件的脚本,但是没有成功,也许我可以禁用自动生成方法,并使用自己的setting.graddle。
可以使用一些帮助。
我遇到了同样的问题,并且我找到了一种在 Cordova 项目中添加本机模块的方法。您可以在功能中使用此功能。
步骤1:
您需要在Android Studio中构建和导入项目。为此,请遵循此。
第2步:
将新模块添加到项目中。为此,请遵循此。
第3步:
在路径<$ c $中找到 GradleBuilder.js
文件c> platforms / android / cordova / lib / builders 。在该文件中,找到编写 settings.gradle
的函数,然后像这样添加模块'include:YourModuleName'
。
对于较旧的 Cordova 版本, settings.gradle
书写功能位于 build.js
路径为 platforms / android / cordova / lib
现在您可以照常通过终端来构建 Cordova 项目。
I have created a Cordova App and added a Native module to the Android project.
I have added dependencies for the module to the project, and everything works fine if I use android studio build.
However, when I execute command 'cordova build android', the file settings.gradle is auto-generated to a default setting which looks like:
// GENERATED FILE - DO NOT EDIT
include ":"
include ":CordovaLib"
As a result, build always fails due to unable to locate module 'mymodule' even if I defined him in settings.gradle.
I tried to find the script that generate the settings.graddle file but without success, maybe I can disable the auto generate method, and use my own setting.graddle.
Could use some help.
I'm having the same issue and i found a way to adding native modules in Cordova project. You can use this in feature.
Step 1:
You need build and import the project in Android Studio. For that please follow this.
step 2:
Add a new module to the project. For that please follow this.
step 3:
Find the GradleBuilder.js
file in path platforms/android/cordova/lib/builders
. In that file, find the function which is writing settings.gradle
and add your module like this 'include ":YourModuleName"'
.
for older Cordova version the settings.gradle
writting function is placed in build.js
path is platforms/android/cordova/lib
Now you can build your Cordova project as usual via terminal.
这篇关于Cordova项目添加Android本机模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!