首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android中嵌入OSGi Felix

在Android中嵌入OSGi Felix
EN

Stack Overflow用户
提问于 2015-11-20 18:30:10
回答 1查看 415关注 0票数 2

我的问题与旧的未解决的问题Android embedded Felix missing requirement osgi.ee非常相关。

我只是将OSGi Felix 5.4.0的一个实例嵌入到一个安卓应用程序中,并试图在其中安装一个纯Java非常简单的捆绑包,由以下代码表示:

代码语言:javascript
复制
@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在它自己的清单中:

代码语言:javascript
复制
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应用程序中到底做了什么:

代码语言:javascript
复制
@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“ ……

我真的不知道发生了什么,感谢大家的回答。

EN

回答 1

Stack Overflow用户

发布于 2017-08-09 14:01:44

我可以通过将以下属性设置为felix来解决这个问题:

代码语言:javascript
复制
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\"");
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33833637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档