我是Cordova插件开发人员的新手。
我想编写一个能够打开新的android Activity 并显示一些广告的插件。
因此,我遵循了一个简单的教程here。效果很好,符合预期。
下一步是将此Android Studio Gradle项目包括到我的插件中。
我的第一次尝试:将gradle项目添加到我的cordova插件的子文件夹中,并将以下行添加到plugin.xml文件中:
<framework src="libs/Broper/build.gradle" custom="true" type="gradleReference" />
我也试过了:
<framework src="libs/Broper/app/build.gradle" custom="true" type="gradleReference" />
不起作用。所以我无法将该Android Studio项目的类导入到我的插件Java文件中。
然后,一个更好的解决方案(我认为是)是添加一个AAR。但是我什至不知道该怎么做才能在我的cordova插件中添加该AAR。
因此,问题是:如何以正确的方式向我的cordova插件添加android studio项目(或库)?
最佳答案
这是我将gradle引用与Cordova插件一起使用所做的工作,我认为这可能会对您有所帮助。
全局结构:
pluginFolder/
build-extras.gradle
plugin.xml
yourDirContainingYourAAR/
src/
android/
yourFile.gradle
myPlugin.java
将您的库(例如
foo.aar
)放入yourDirContainingYourAAR
目录(如果需要,请创建)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="yourDirContainingYourAAR/foo.aar" target="libs/foo.aar" />
</platform>
yourFile.gradle
中:repositories{
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'foo', ext:'aar')
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
plugin.xml
相同的级别)中,创建一个build-extras.gradle
。如果需要,根据您的项目需求添加或删除
minSdkVersion
和targetSdkVersion
:android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}