我的問題是非常相關的舊未解決問題Android embedded Felix missing requirement osgi.ee。在Android中嵌入OSGi Felix
我只是嵌入OSGi的菲利克斯5.4.0的實例爲Android應用程序,並試圖安裝在它純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
下面的代碼說明我究竟d ID在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;
}
}
它seeems很簡單,但我得到以下錯誤,當我嘗試啓動ExampleBattery軟件包:
5月3日至29日:29:44.942 :E/Felix(8156):無法啓動Bundle「ExampleBattery.ExampleBattery」: org.osgi.framework.BundleException:Unable to resolve ExampleBattery.ExampleBattery [1](R 1.0): 缺少要求[ExampleBattery.ExampleBattery [ 1](R 1.0)] osgi.ee; (&(osgi.ee = JavaSE)(版本= 1.7)) 未解決的需求:[[ExampleBattery.ExampleBattery [1](R 1.0)] osgi.ee; (&(osgi.ee =的JavaSE)(版本= 1.7))
這種情況是很奇怪的,因爲費利克斯利用其default.properties配置文件目前出口的Java默認情況下felix.jar:
....
org.osgi.framework.system.capabilities = $ {eecap - $ {java.specification.version}}eecap-1.8 = osgi.ee ; osgi.ee = 「的OSGi /最小值」;版本:List =「1.0,1.1,1.2」,osgi.ee; osgi.ee = 「JavaSE的」;版本:List =「1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8」
eecap-1.7 = osgi.ee; osgi.ee = 「的OSGi /最小值」;版本:List =「1.0,1.1,1.2」,osgi.ee; osgi.ee = 「JavaSE的」;版本:列表=「1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7」
....
我真的不知道發生了什麼,感謝所有的答案。