如何将原生模块添加到Cordova Android项目中? [英] How to add native module to Cordova Android project?

查看:208
本文介绍了如何将原生模块添加到Cordova Android项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向Cordova Android项目添加一个本机(集成测试)模块.

I want to add a native (integration test) module to a Cordova Android project.

对于完全本机的项目,您只需添加一个新模块,然后提交并完成该模块即可.但是对于Cordova来说,我当然并不想弄乱生成的Android项目,因为其中一些更改可能会在构建等过程中丢失.

For fully native projects, you just add a new module, commit and be done with it. But for Cordova I of course don't really want to mess with the generated Android project as some of these changes might be lost on build etc.

通过将模块文件夹放置在Cordova Android文件夹之外并将其添加到settings.gradle,我得到了模块手动工作的概念:

I got a Poof of Concept of the module working manually by having the module folder outside of the Cordova Android folder and adding this to settings.gradle:

include ':module-androidTest'
project(':module-androidTest').projectDir = new File("../module-tests")

但是该文件的第1行当然已经说过

But of course line 1 of that file already says

// GENERATED FILE - DO NOT EDIT

还有其他方法可以向Cordova Android项目添加其他模块吗?

Is there any other way to add additional modules to a Cordova Android project?

我研究或考虑过的一些方法:

Some approaches I researched or thought about:

  • 我可以用build-extras.gradle这样做吗? (我不认为settings.gradle是在构建extras和build.gradle之前的几个步骤,对吧?)

  • Can I somehow do this with build-extras.gradle? (I don't think so as settings.gradle is several steps before build-extras and build.gradle, right?)

较旧的StackOverflow问题建议手动编辑GradleBuilder.js文件: https://stackoverflow.com/a/35504783/252627 但是,当然,每当我完全生成一个新的Cordova项目时,这一切都会丢失.不是一个好主意,对吗?

Older StackOverflow questions suggest manually editing a GradleBuilder.js file: https://stackoverflow.com/a/35504783/252627 But of course this would get lost each time I completely generate a new Cordova project. Not a good idea, correct?

我可以通过Cordova插件以某种方式解决此问题吗?我知道这些可以加载框架等-也许也可以以某种方式添加模块?

Can I maybe work around this somehow via a Cordova plugin? I know these can load frameworks etc - maybe also a module somehow?

推荐答案

我认为您可以使用自定义插件完成所需的工作,该插件可以使用如下框架标签扩展基本gradle配置:

I think what you are looking for can be done using a custom plugin which can extend the base gradle config using a framework tag like this:

<framework src="relative/path/to/your/gradlefile/*.gradle" custom="true" type="gradleReference" />

这通常是cordova-android项目的扩展方式.

This is how a cordova-android project is usually extended.

这篇关于如何将原生模块添加到Cordova Android项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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