科尔多瓦插件包括Android库(Gradle) [英] Cordova Plugin include Android Library (Gradle)

查看:128
本文介绍了科尔多瓦插件包括Android库(Gradle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Cordova插件中包含这个Android .

I would like to include this Android library in a Cordova Plugin.

该库本身由Gradle管理,如Github链接所示.该库的开发人员仅提供指南如何在Android Studio项目中使用它,但是我想为此库创建Cordova插件包装程序,因此我想将其包含在插件中.

The library itself is managed by Gradle, as can be seen in the Github link. The developers of the library only provide guide how to use it in a Android Studio project, but I would like to create Cordova Plugin wrapper for this library, so I want to include it with the plugin.

我的插件具有以下结构:

My plugin has following structure:

-root
   -plugin.xml
   -lib
     -fliclib-android (this is a cloned library from the github link)
   -src
     -android
       -MyPlugin.java
   -www
     -MyPlugin.js

在plugin.xml里面,我有:

Inside of plugin.xml I have:

...
<js-module src="www/MyPlugin.js" name="MyPlugin">
    <clobbers target="MyPlugin" />
</js-module>

<!-- android -->
<platform name="android">
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="MyPlugin">
            <param name="android-package" value="com.mypackage.cordova.MyPlugin"/>
        </feature>
    </config-file>

    <source-file src="src/android/MyPlugin.java" target-dir="src/com/mypackage/cordova" />
    <framework src="lib/fliclib-android/build.gradle" custom="true" type="gradleReference" />

</platform>
...

我也尝试过:

<framework src="lib/fliclib-android/fliclib/build.gradle" custom="true" type="gradleReference" />
<framework src="lib/fliclib-android/" custom="true" />
<framework src="lib/fliclib-android/fliclib/src/main/" custom="true" />

... 我也尝试在lib/fliclib-android/fliclib/src/main中创建自己的Gradle文件.到目前为止没有运气.当我尝试运行cordova build进程时,通常最终会遇到一堆错误,表明没有加载库中的类/符号.

... I have also tried creating my own Gradle file inside lib/fliclib-android/fliclib/src/main. So far no luck. When I try to run the cordova build process, what I usually end up with is bunch of errors indicating that no class/symbol from the library was loaded.

是否甚至可以包含这样的项目?如果我可以从Github引用它,那也很好,但是在文档中我没有找到这样的选择. 还是我必须创建一个aar文件?并加载吗?我没有尝试过该选项,但是我只想在万不得已的情况下尝试.

Is it even possible to include project like this? It would be also great if I could just reference it from Github, but in the docu I did not find such option. Or do I have to create an aar file? And load that? I have not tried that option, but I would like to try that only in the last resort case.

谢谢!

推荐答案

我采用了另一种方法.有趣的是,我开发了完全相同的插件,却没有找到您的项目!

I followed a different approach. It is funny that I developed the very same plugin and I didn't found your project!

我的方法是在我的项目中添加一个自定义的build.gradle文件.在plugin.xml中,使用framework标记指定build.gradle的位置:

My approach was to add a custom build.gradle file in my project. In the plugin.xml use the framework tag to specify the build.gradle location:

<!-- android -->
<platform name="android">
    <framework src="src/android/build.gradle" custom="true" type="gradleReference" />
</platform>

然后,build.gradle的内容如下:

Then, the build.gradle contents are as follows:

repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.50ButtonsEach:fliclib-android:ec1cdc3fbe'
}

它使用Jitpack来获取依赖项.尽管在CordGap Build云解决方案中构建时仍然遇到困难,但在Cordova上运行效果很好.

It uses Jitpack to fetch the dependencies. It's working nice on Cordova, though I'm still having trouble building in the PhoneGap Build cloud solution.

这是我的插件,iOS支持正在进行中

This is my plugin, iOS support is on the way:

https://github.com/jguix/Cordova-Flic

这篇关于科尔多瓦插件包括Android库(Gradle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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