我的问题与旧的未解决的问题Android embedded Felix missing requirement osgi.ee非常相关。
我只是将OSGi Felix 5.4.0的一个实例嵌入到一个安卓应用程序中,并试图在其中安装一个纯Java非常简单的捆绑包,由以下代码表示:
@Component
public class ExampleBattery
{
@Activate
public void activate()
{
Thread t = new Thread(new Work());
t.start();
}
private class Work implements Runnable
{
boolean continueLoop = true;
@Override
public void run()
{
while (continueLoop)
{
System.out.println("hello");
try
{
Thread.sleep(2500);
}
catch (InterruptedException e)
{
continueLoop = false;
}
}
}
}
}它显然需要osgi.ee=JavaSE在它自己的清单中:
Manifest-Version: 1.0
Bnd-LastModified: 1448019954932
Bundle-ManifestVersion: 2
Bundle-Name: ExampleBattery.ExampleBattery
Bundle-SymbolicName: ExampleBattery.ExampleBattery
Bundle-Version: 1.0.0
Created-By: 1.8.0_66 (Oracle Corporation)
Private-Package: user.producer.battery
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"
Service-Component: OSGI-INF/user.producer.battery.ExampleBattery.xml
Tool: Bnd-3.0.0.201509101326下面的代码显示了我在Android应用程序中到底做了什么:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
launchFramework();
}
private void launchFramework()
{
// properties Map for the Felix instance
Map<String, String> configMap = configMap = new HashMap<String, String>();
// set some properties (like Felix's cache directory, etc.)
configMap.put("felix.cache.rootdir", felixBaseDir);
configMap.put("org.osgi.framework.storage", FELIX_CACHE_DIR_NAME);
try
{
// create and initialize the instance of the Framework
this.felixInstance = new Felix(configMap);
this.felixInstance.init();
Log.i("Felix", "Framework successfully created and initialized");
// simply use the Bundle context of the Felix
// instance to install ExampleBattery from the project's assets folder
installBasicBundlesFromAssets();
Log.i("Felix", "All basic Bundles installed successfully");
// start the framework
this.felixInstance.start();
Log.i("Felix", "Framework successfully started");
//
Log.i("Felix", "Starting installed Bundles ...");
// simply call "start()" on all the installed Bundles
if (startInstalledBundles())
{
Log.i("Felix", "ALL OK");
}
}
catch (Exception ex)
{
Log.e("Felix", "Could not create framework: " + ex);
return;
}
}它非常简单,但是当我尝试启动ExampleBattery包时,我得到了以下错误:
(&(osgi.ee=JavaSE)(version=1.7))]:03-29 05:29:29:44.942: E/Felix(8156):无法启动捆绑" ExampleBattery.ExampleBattery ":org.osgi.framework.BundleException:无法解决ExampleBattery.ExampleBattery 1:缺失需求[ExampleBattery.ExampleBattery 1] osgi.ee;(&(osgi.ee=JavaSE)(version=1.7))未解决的要求:[[ExampleBattery.ExampleBattery 1] osgi.ee;ExampleBattery.ExampleBattery
这种情况非常奇怪,因为Felix默认使用其default.properties配置文件导出felix.jar中的
…… org.osgi.framework.system.capabilities=${eecap-${java.specification.version}} eecap-1.8= osgi.ee;osgi.ee=“OSGi/最小值”;version:List="1.0,1.1,1.2",osgi.ee;osgi.ee="JavaSE";osgi.ee=“JavaSE” version:List="1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7“eecap-1.7= osgi.ee;osgi.ee="OSGi/Minimum";version:List="1.0,1.1,1.2",osgi.ee;osgi.ee="JavaSE";version:List=”1.0,1.1,1.2“ ……
我真的不知道发生了什么,感谢大家的回答。
发布于 2017-08-09 14:01:44
我可以通过将以下属性设置为felix来解决这个问题:
configMap.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "osgi.ee; osgi.ee=\"JavaSE\";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8\"");https://stackoverflow.com/questions/33833637
复制相似问题