Skip to content Skip to sidebar Skip to footer

Android/phonegap: Using Third-party Libraries In Plugin-development

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 b

Solution 1:

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

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

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(thisiswhere the .jar is located)
     +www (empty, not referencing any .js)
     +plugin.xml

For brevity, plugin.xml as follows:

<?xml version="1.0" encoding="UTF-8"?><pluginxmlns="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 --><platformname="android"><config-filetarget="res/xml/config.xml"parent="/*"><featurename="org.apache.commons.net"><paramname="android-package"value="org.apache.commons.net"/></feature></config-file><source-filesrc="src/android/commons-net-2.2.jar"target-dir="libs"framework="true" /></platform></plugin>

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

Solution 2:

To add external library, basically all you have to do is copy the jar to the /libs folder.

Here you have a bad import in your source.

import is used to import a class by specifying the package name followed by the class name and here you only specify the class name, so the error "cannot find symbol class osc" you are having is because there is no class osc.

You should use either

  • import com.illposed.osc.*; if you want to import all classes from the package
  • or add an import for each class from the package that you are going to use.

And if you want make the plugin installable using the CLI or phonegap build, you also have to update plugin.xml to add the copy of the jar file.

ps in case you don't know, you won't be able to use classes from com.illposed.osc.ui as they are using swing and designed for the jvm and not android.

Post a Comment for "Android/phonegap: Using Third-party Libraries In Plugin-development"