Android embedded Felix missing requirement osgi.ee

血红的双手。 提交于 2019-12-25 04:28:08

问题


I'm trying to convince an embedded Apache Felix on Android to start an external bundle.
So far I have managed to embed the felix.jar into its own APK and run it as an activity. Within this activity I'm able to install outside bundles from jar files. Unfortunately whenever I try to move on and start one of these bundles I get the following error:

Encountered exception when starting bundle:

Unresolved constraint in bundle com.example.hellofelix [1]:        
Unable to resolve 1.0:             
missing requirement [1.0] osgi.ee;                           
(&(osgi.ee=JavaSE)(version=1.7.0))     

As com.example.hellofelix is the package name for my test application this suggests that my app is missing the osgi.ee package required by the constraint of JavaSE 1.7.0.

How exactly do I solve this problem?
Do I have to specify en extra export in my app, import something or just add another bundle?

My bundle's code:

Activator:

package com.example.dictionary;

import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.example.dictionary.service.DictionaryBundle;

public class Activator implements BundleActivator {

  public void start(BundleContext context) throws Exception {
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put("Language", "de-en");
    context.registerService(DictionaryBundle.class.getName(), new DictionaryBundleImpl(), props);
  }

  public void stop(BundleContext context) throws Exception {
    // NOTE: The service is automatically unregistered.
  }

} 

Interface:

package com.example.dictionary.service;

public interface DictionaryBundle {

    public String translate(String wordToTranslate);

}

Implementation:

package com.example.dictionary;

import java.util.Hashtable;

import com.example.dictionary.service.DictionaryBundle;

public class DictionaryBundleImpl implements DictionaryBundle {

    private Hashtable<String, String> dictionary;

    public DictionaryBundleImpl() {
        dictionary = new Hashtable<>();

        dictionary.put("ente", "duck");
        dictionary.put("hund", "dog");
        dictionary.put("kuh", "cow");
        dictionary.put("katze", "cat");
        dictionary.put("maus", "mouse");
    }

    public String translate(String wordToTranslate) {
        return dictionary.get(wordToTranslate);
    }

}

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-SymbolicName: com.example.hellofelix
Export-Package: com.example.dictionary.service
Bundle-Name: TestBundle
Bundle-Version: 1.4.2.qualifier
Bundle-ManifestVersion: 2
Bundle-Activator: com.example.dictionary.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Vendor: None

Thank you very much!


回答1:


The bundle's manifest says that it requires JavaSE 1.7. And your runtime does not supply that JRE. So it fails to resolve as it should.

You can either change the bundle to target a different osgi.ee (the one in Android) or you can tell Felix to lie and claim that the osgi.ee is JavaSE 1.7.

That is, either change the requirement in the bundle or the capability provided by the framework.



来源:https://stackoverflow.com/questions/27985701/android-embedded-felix-missing-requirement-osgi-ee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!