2015-11-20 70 views
2

我的问题是非常相关的旧未解决问题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”
....

我真的不知道发生了什么,感谢所有的答案。

回答

1

我可以解决通过设置以下属性,这个问题给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\""); 
相关问题