Cordova插件开发 - 添加aar [英] Cordova plugin development - adding aar

查看:677
本文介绍了Cordova插件开发 - 添加aar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的cordova插件开发的东西。
我想写一个插件,它能够打开一个新的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.

下一步是将这个Android Studio Gradle项目包含在我的插件中。

Next step is to include this Android Studio Gradle project to my plugin.

我的第一次尝试:将gradle项目添加到我的cordova插件的子文件夹,并添加以下行到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" />

也尝试过:

<framework src="libs/Broper/app/build.gradle" custom="true" type="gradleReference" />

gradova文件被cordova识别。但是东西不工作。所以我不能导入Android工作室项目的类,我的插件的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在我的cordova插件。

Then a better solution (I thought so) is to add a AAR instead. But there I don't even have a clue what to do to add that AAR in my cordova plugin.

所以,问题是:如何添加一个android音频

So, the question is: How do I add a android atudio aroject (or library) to my cordova plugin the right way?

推荐答案

这是我做了什么使用gradle引用

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

放入你的库,例如 foo.aar ,在 yourDirContainingYourAAR 目录(如果需要创建它)

Put your library, say foo.aar, in the yourDirContainingYourAAR directory (create it if needed)


  • p>在 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>


  • 在gradle档案 yourFile.gradle

    repositories{    
      jcenter()
      flatDir {
          dirs 'libs'
       }
    }
    
    dependencies {
       compile(name:'foo', ext:'aar')
    }
    
    android {
      packagingOptions {
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
      }
    }
    


  • 在插件的根文件夹 .xml )创建一个 build-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'
       }
    }
    


  • 这篇关于Cordova插件开发 - 添加aar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆