gpt4 book ai didi

java - 在 Android 中嵌入 OSGi Felix

转载 作者:行者123 更新时间:2023-11-30 10:53:57 28 4
gpt4 key购买 nike

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

我简单地将 OSGi Felix 5.4.0 的实例嵌入到一个 Android 应用程序中,并尝试在其中安装一个非常简单的 pure-Java Bundle,由以下代码:

@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 在它自己的 list 中:

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 Bundle 时出现以下错误:

03-29 05:29:44.942: E/Felix(8156): Unable to start the Bundle "ExampleBattery.ExampleBattery":org.osgi.framework.BundleException: Unable to resolve ExampleBattery.ExampleBattery [1](R 1.0):missing requirement [ExampleBattery.ExampleBattery [1](R 1.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.7))Unresolved requirements: [[ExampleBattery.ExampleBattery [1](R 1.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.7))]

这种情况很奇怪,因为 Felix 默认使用 felix.jar 中的 default.properties 配置文件导出 Java:

....
org.osgi.framework.system.capabilities=${eecap-${java.specification.version}}

eecap-1.8= 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,1.3,1.4,1.5,1.6,1.7,1.8"
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,1.3,1.4,1.5,1.6,1.7"
....

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

最佳答案

我可以通过将以下属性设置为 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\"");

关于java - 在 Android 中嵌入 OSGi Felix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33833637/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com