Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly include an external jar file for a cordova plugin?

I am trying to make a simple cordova android plugin that requires classes defined in a jar file. I have a test project here, that includes the example usage & a simplified version of my plugin.

In my plugin.xml, I have this:

<platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="Pebble">
                <param name="android-package" value="com.jetboystudio.pebble.PebblePGPlugin"/>
            </feature>
        </config-file>
        <source-file src="src/android/PebblePGPlugin.java" target-dir="src/com/jetboystudio/pebble" />
        <source-file src="src/android/libs/pebble_kit.jar" target-dir="libs" />
    </platform>

In my test project, I have pebblekit jar in-place where it needs to be (I think): plugins/com.jetboystudio.pebble.PebblePGPlugin/src/android/libs/pebble_kit.jar

When I "cordova build" I get no errors, but when I install the apk-file I get "Class not found" in Chrome device inspect. I am assuming this class it can't find is one of the classes defined in pebble_kit.jar. Also, it doesn't seem to be copying this file into platforms/android.

If I could just debug better (which class is not found?) that might be a good start, if no one has the actual answer of why this doesn't work.

like image 257
konsumer Avatar asked Aug 22 '14 01:08

konsumer


People also ask

Are plugins JAR files?

A plugin is most commonly a Java Jar file that contains a set of resource files (e.g., color tables) and/or Java class files.

How do I import a jar file into flutter?

Open the plugin project in your IDE. After that add the third-party jars to the Java classpath. In IDE, click Project Structure/Modules/Select pluginName_android / Dependencies tab/Green PlusSign/jars or directories. Later select the individual jars or the whole folder.

What are different plugins in Cordova?

Plugin APIs camera: This plugin is used to provide an interface to enable the device camera. It can also select the images from the device storage. contacts: It allows access to the device contacts. device: It provides an interface to retrieve the information about the hardware and software.


2 Answers

Your plugin.xml is correct.

Do not edit the plugin.xml after you have added/install the plugin into the project.
When you run cordova build or prepare it will not process the native parts of plugin.xml, it only get's process on cordova plugin add

Update your plugin repo/folder with plugin.xml containing the jar file and the line that you have is correct.

Then do

cordova plugin rm

cordova plugin add

cordova build

The end result verify that /platforms/android/libs/pebble_kit.jar is present after cordova build.

like image 153
csantanapr Avatar answered Oct 18 '22 12:10

csantanapr


You can also add a jar file with:

<lib-file src="src/android/libs/pebble_kit.jar" />

This will add the jar to platforms/android/app/libs/

like image 27
Lindsay-Needs-Sleep Avatar answered Oct 18 '22 11:10

Lindsay-Needs-Sleep