科尔多瓦插件开发 - 添加AAR [英] Cordova plugin development - adding aar
问题描述
我是新来的科尔多瓦插件开发的东西。 我想写一个插件,它能够打开一个新的Android activty并显示一些广告。
I am new to the cordova plugin development stuff. I want to write a plugin which is able to open a new android activty and showing some advertisement.
于是,我跟着一个简单的教程这里。这工作得很好,符合市场预期。
So I followed a simple tutorial here. That works very well and as expected.
下一步是包括这个机器人工作室摇篮的项目我的插件。
Next step is to include this Android Studio Gradle project to my plugin.
我的第一次尝试:添加摇篮项目,我科尔多瓦插件的子文件夹,并添加以下行到plugin.xml文件中:
My first try: Adding the gradle project to a subfolder of my cordova plugin and adding the following line to the plugin.xml file:
<framework src="libs/Broper/build.gradle" custom="true" type="gradleReference" />
我也尝试过:
also I tried:
<framework src="libs/Broper/app/build.gradle" custom="true" type="gradleReference" />
该graddle文件由科尔多瓦认可。可是,我不工作。所以,我无法导入机器人工作室项目的类别,以我的插件java文件。
The graddle files are recognised by cordova. But something don't work. So i can't import the classes of that android studio project to my plugin java files.
然后一个更好的解决方案(我是这么认为的)是添加一个AAR代替。但是,我甚至不有克卢厄怎样做才能添加AAR在我的科尔多瓦插件。
Then a better solution (I thought so) is to add a AAR instead. But there I don't even have a cloue what to do to add that AAR in my cordova plugin.
所以,问题是:如何添加一个机器人atudio aroject(或库),以我的科尔多瓦插件的正确方法
So, the question is: How do I add a android atudio aroject (or library) to my cordova plugin the right way?
推荐答案
下面是我对我所做的使用与科尔多瓦插件一个摇篮的参考,我想这可能会帮助你。
Here's what I've done to use a gradle reference with a Cordova plugin, I think this might help you.
全球结构:
pluginFolder/
build-extras.gradle
plugin.xml
yourDirContainingYourAAR/
src/
android/
yourFile.gradle
myPlugin.java
把AAR文件中的yourDirContainingYourAAR'目录(如果需要创建它)
Put the aar file in the 'yourDirContainingYourAAR' directory (create it if needed)
-
在
的plugin.xml
文件:
<platform name="android">
<!-- your configuration elements, references, source files, etc... -->
<framework src="src/android/yourFile.gradle" custom="true" type="gradleReference" />
<resource-file src="libs/foo.aar" target="libs/foo.aar" />
</platform>
在摇篮文件 yourFile.gradle
:
repositories{
jcenter()
flatDir{
dirs 'yourDirContainingYourAAR'
}
}
dependencies {
compile(name:'yourAARFileWithoutExtension', ext:'aar')
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
在根文件夹你的插件(同一水平的plugin.xml
)创建一个构建-extras.gradle
。
如果需要,添加或删除的minSdkVersion和targetSdkVersion根据项目的需要:
In the root folder of your plugin (same level as plugin.xml
) create a build-extras.gradle
.
If needed, add or remove minSdkVersion and targetSdkVersion according to your project needs :
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
这篇关于科尔多瓦插件开发 - 添加AAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!