添加依赖项到Android Cordova插件

时间:2022-09-12 20:28:53

I'm building a Cordova Android plugin. I want to use a 3rd party View inside an Intent that is created by the plugin (specifically scissors). Normally (in non Cordova projects) I would go to my project's build.gradle file and add it like this:

我正在构建一个Cordova Android插件。我想在插件(特别是剪刀)创建的Intent中使用第三方视图。通常(在非Cordova项目中)我会转到我的项目的build.gradle文件并添加如下:

dependencies {
compile 'com.lyft:scissors:1.0.1' }

But it seems like the build.gradle file in my plugin's project wasn't meant to be touched? What is the proper way to add a dependency to a plugin project, to support both builds via Cordova and builds via Android Studio? Same question, but for a local project (not hosted on GitHub).

但似乎我的插件项目中的build.gradle文件似乎没有被触及?向插件项目添加依赖项的正确方法是什么,通过Cordova支持构建并通过Android Studio构建?同样的问题,但对于本地项目(不在GitHub上托管)。

2 个解决方案

#1


14  

You have to use your own gradle file and link it on the plugin.xml like this

您必须使用自己的gradle文件并将其链接到plugin.xml上,如下所示

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

You have to put that tag on the plugin.xml, so on plugin install it's read and cordova handles it (not sure how it works internally, but I suppose that it copies the values from your custom .gradle to the main build.gradle). So you can't test it on your current project, you have to create a new project and add the plugin and see if it works

你必须把这个标签放在plugin.xml上,所以在插件安装它的读取和cordova处理它(不知道它是如何在内部工作,但我想它将值从你的自定义.gradle复制到主build.gradle) 。因此,您无法在当前项目上测试它,您必须创建一个新项目并添加插件,看它是否有效

#2


4  

The Cordova Android plugins doc (in "Adding Dependency Libraries") specify that you can add dependency libraries with the <framework> tag in your plugin.xml.

Cordova Android插件doc(在“添加依赖库”中)指定您可以在plugin.xml中添加带有 标记的依赖库。

So for the scissors dependency you can use:

因此,对于剪刀依赖,您可以使用:

<platform name="android">
    <framework src="com.lyft:scissors:1.0.1" />

#1


14  

You have to use your own gradle file and link it on the plugin.xml like this

您必须使用自己的gradle文件并将其链接到plugin.xml上,如下所示

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

You have to put that tag on the plugin.xml, so on plugin install it's read and cordova handles it (not sure how it works internally, but I suppose that it copies the values from your custom .gradle to the main build.gradle). So you can't test it on your current project, you have to create a new project and add the plugin and see if it works

你必须把这个标签放在plugin.xml上,所以在插件安装它的读取和cordova处理它(不知道它是如何在内部工作,但我想它将值从你的自定义.gradle复制到主build.gradle) 。因此,您无法在当前项目上测试它,您必须创建一个新项目并添加插件,看它是否有效

#2


4  

The Cordova Android plugins doc (in "Adding Dependency Libraries") specify that you can add dependency libraries with the <framework> tag in your plugin.xml.

Cordova Android插件doc(在“添加依赖库”中)指定您可以在plugin.xml中添加带有 标记的依赖库。

So for the scissors dependency you can use:

因此,对于剪刀依赖,您可以使用:

<platform name="android">
    <framework src="com.lyft:scissors:1.0.1" />