向 Android Cordova 插件添加依赖项

Add a dependency to an Android Cordova plugin(向 Android Cordova 插件添加依赖项)
本文介绍了向 Android Cordova 插件添加依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在构建一个 Cordova Android 插件.我想在 由插件创建Intent 中使用第 3 方 View(特别是 剪刀).通常(在非 Cordova 项目中)我会转到我的项目的 build.gradle 文件并像这样添加它:

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:

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

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

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).

推荐答案

你必须使用你自己的 gradle 文件然后像这样链接到 plugin.xml

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

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

您必须将该标签放在 plugin.xml 上,因此在插件安装时它会被读取并由 cordova 处理(不确定它是如何在内部工作的,但我想它会从您的自定义 .gradle 到主 build.gradle).

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

这篇关于向 Android Cordova 插件添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)