Add a dependency to an Android Cordova plugin

安稳与你 提交于 2019-11-29 12:27:40

问题


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' }

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


回答1:


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

<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




回答2:


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

So for the scissors dependency you can use:

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


来源:https://stackoverflow.com/questions/34314996/add-a-dependency-to-an-android-cordova-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!