简体   繁体   中英

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.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM