如何正确包含cordova插件的外部jar文件?

kon*_*mer 15 java android cordova

我正在尝试制作一个简单的cordova android插件,它需要在jar文件中定义的类.我这里有一个测试项目,其中包括我的插件的示例用法和简化版本.

在我的plugin.xml中,我有这个:

<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>
Run Code Online (Sandbox Code Playgroud)

在我的测试项目中,我有pebblekit jar就位(我认为):plugins/com.jetboystudio.pebble.PebblePGPlugin/src/android/libs/pebble_kit.jar

当我"cordova build"时,我没有错误,但是当我安装apk文件时,我在Chrome设备中检查了"Class not found".我假设这个类找不到是pebble_kit.jar中定义的类之一.此外,它似乎没有将此文件复制到platforms/android.

如果我可以更好地调试(找不到哪个类?)这可能是一个好的开始,如果没有人有实际答案为什么这不起作用.

小智 11

plugin.xml是对的.

plugin.xml将插件添加/安装到项目后,请不要编辑.
当你运行cordova构建或准备它不会处理plugin.xml的原生部分时,它只会在cordova插件上添加进程

更新您的插件repo /文件夹,plugin.xml其中包含jar文件和您拥有的行是正确的.

然后做

cordova plugin rm

cordova plugin add

cordova build
Run Code Online (Sandbox Code Playgroud)

最终结果验证了/platforms/android/libs/pebble_kit.jarcordova构建后的存在.