安卓/ PhoneGap的:在插件开发使用第三方库 [英] Android/PhoneGap: Using third-party libraries in plugin-development

查看:192
本文介绍了安卓/ PhoneGap的:在插件开发使用第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个的PhoneGap /科尔多瓦插件,是应该提供一个插座,用于发送和接收消息的OSC(开放声音控制)。为了这个目的,我想使用 JavaOSC 但我不确定如何包括库到我的项目。

I'm working on a PhoneGap/Cordova plugin that's supposed to provide a socket for sending and receiving OSC messages (Open Sound Control). For that purpose I'd like to use JavaOSC but I'm uncertain about how to include the library into my project.

我使用的是Android Studio和我已经基本沿袭的本教程建立我的项目。首先我把原始JavaOSC类文件在同一目录作为我的OSCPlugin.class并放置在进口申报的,以我的OSCPlugin.class的:

I'm using Android Studio and I've basically followed this tutorial to set up my project. First I placed the raw JavaOSC class-files in the same directory as my OSCPlugin.class and placed the import declarations at the to of my OSCPlugin.class:

import com.illposed.osc;

这没有奏效。

作为下一步我试图从行家在项目内的模块设置添加库。我能够从Maven的下载jar文件和安装把它们放到/平台/安卓/库。在该模块'机器人'的设置,我可以看到,Android的API 17'应该被用来作为SDK,包括科尔多瓦-3.1.0和com.illposed.osc:javaosc芯:0.2 - 无论激活。我能看到科尔多瓦-3.1.0.jar以及javaosc核心 - 0.2.jar,含com.illposed.osc在Android的Studio中导航。

As a next step I tried to add the library from maven within the project's module settings. I was able to download the jar files from maven and install put them into /platforms/android/libs. Within the settings for the module 'android' I can see that 'Android API 17' is supposed to be used as SDK, including cordova-3.1.0 and com.illposed.osc:javaosc-core:0.2 - both activated. I can see the cordova-3.1.0.jar as well as javaosc-core-0.2.jar, containing com.illposed.osc in the navigator within Android Studio.

但是,试图编译我的项目时,我得到:

However, when trying to compile my project I get:

Gradle: cannot find symbol class osc

从内部OSCPlugin.class触发包含上述进口报关

triggered from within OSCPlugin.class that contains the above mentioned import declaration

我有Java的就更少了Android开发经验非常少。但我很想解决这个谜,并开始。我已经搜查了Java文档,但问题并不仅仅在于在Java,而是内部的Andr​​oid项目的结构。

I have very little experience with Java and even less with Android development. But I'd be interested in solving this riddle and get started. I have searched the Java docs but the problem doesn't merely lie within Java but rather within the structure of the Android project.

我会很感激,如果有人能够阐明这个问题的一些情况。任何提示的高度AP preciated!

I'd be thankful if someone could shed some light on this issue. Any hint's highly appreciated!

推荐答案

有关我的PhoneGap项目之一我需要的 Apache的百科全书网,努力遵循这些的步骤

For one of my Phonegap projects I needed the Apache Commons Net, trying to follow these steps:

...
<source-file src="src/android/xxx.jar" target-dir="libs" framework="true" />
<source-file src="src/android/MyPlugin.java" target-dir="src/com/mypackage" />
...

不幸的是,没有成功。诀窍是嵌入在另一个插件第三方库(以下非常插件结构)。具有org.apache.commons.net作为顶级目录:

unfortunately, without success. The trick was to embed the third-party library in another plugin (following the very plugin structure). Having the org.apache.commons.net as a top level directory:

    org.apache.commons.net
     +src 
       +android(this is where the .jar is located)
     +www (empty, not referencing any .js)
     +plugin.xml

为了简便起见,plugin.xml中如下:

For brevity, plugin.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
           id="org.apache.commons.net"
      version="0.1.0">
    <name>org.apache.commons.net</name>
    <description>org.apache.commons.net</description>
    <license>Apache License, Version 2.0</license>
    <keywords>org.apache.commons.net</keywords>

    <!-- android -->
    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="org.apache.commons.net">
                <param name="android-package" value="org.apache.commons.net"/>
            </feature>
        </config-file>

        <source-file src="src/android/commons-net-2.2.jar" target-dir="libs" framework="true" />    
     </platform>          
</plugin>

假设 org.apache.commons.net 目录位于本地git仓库,将它添加到你的项目是简单,例如:

Assuming the org.apache.commons.net directory is located in your local git repo, adding it to your project is as trivial as:

phonegap local plugin add /path/to/your/org.apache.commons.net

这篇关于安卓/ PhoneGap的:在插件开发使用第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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