Android/PhoneGap: Using third-party libraries in plugin-development

10,668

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.

Share:
10,668
5tefan
Author by

5tefan

Updated on June 12, 2022

Comments

  • 5tefan
    5tefan almost 2 years

    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.

    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;
    

    That didn't work.

    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
    

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

    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.

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