我有plugin.xml文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="pl.jcubic.leash.service" version="1.0.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0">
<name>Exec</name>
<description>Apache Cordova Leash shell service plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,exec,runtime,process,shell,command</keywords>
<js-module name="service" src="www/service.js">
<clobbers target="service"/>
</js-module>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="Service">
<param name="android-package" value="pl.jcubic.leash.Service" />
<param name="onload" value="true" />
</feature>
</config-file>
<source-file src="src/pl/jcubic/leash/Service.java"
target-dir="src/pl/jcubic/leash/Service" />
</platform>
</plugin>
我的插件在Service.java文件中,但现在我想创建超类并在那里放置一些逻辑,所以我的Service.java文件看起来像这样:
package pl.jcubic.leash;
public class Service extends ReflectService {
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
// your init code here
}
public String echo(String input) {
if (input.equals("ping")) {
return "pong";
} else {
return null;
}
}
}
和ReflectService.java看起来像这样:
package pl.jcubic.leash;
public class ReflectService extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
}
...
}
但是当我添加插件并运行cordova运行android时我发现了这个错误:
/home/kuba/projects/jcubic/leash/leash/platforms/android/src/pl/jcubic/leash/Service/Service.java:22: error: cannot find symbol
public class Service extends ReflectService {
^
symbol: class ReflectService
/home/kuba/projects/jcubic/leash/leash/platforms/android/src/pl/jcubic/leash/Service/Service.java:25: error: cannot find symbol
super.initialize(cordova, webView);
^
symbol: variable super
location: class Service
2 errors
如何从android / cordova插件中的同一个包导入类?当我安装了插件时,ReflectService.java文件就在那里。我需要在xml文件中放置多个源文件吗?我怎么能这样做?
答案 0 :(得分:0)
我需要做的就是将另一个源文件放入xml文件中:
<source-file src="src/pl/jcubic/leash/Service.java"
target-dir="src/pl/jcubic/leash/Service" />
<source-file src="src/pl/jcubic/leash/ReflectService.java"
target-dir="src/pl/jcubic/leash/Service" />