我开发了一个小型 EMF 项目作为 OSGi Bundle。现在我想在带有 Apache Felix 的 Android 上使用它。 EMF 使用一些标准的 Java 库。像 java.xml.xxx。通常 OSGi 系统包会导出这些。但在我的 android 案例中,它看起来像这样:
System Bundle (0)
Bundle-Description = This bundle is system specific; it implements various system services.
Bundle-ManifestVersion = 2
Bundle-Name = System Bundle
Bundle-SymbolicName = org.apache.felix.framework
Bundle-Version = 4.1.0.SNAPSHOT
Export-Package = org.osgi.framework; version="1.6.0", org.osgi.framework.launch; version="1.0.0", org.osgi.framework.wiring; version="1.0.0", org.osgi.framework.startlevel; version="1.0.0", org.osgi.framework.hooks.bundle; version="1.0.0", org.osgi.framework.hooks.resolver; version="1.0.0", org.osgi.framework.hooks.service; version="1.1.0", org.osgi.framework.hooks.weaving; version="1.0.0", org.osgi.service.packageadmin; version="1.2.0", org.osgi.service.startlevel; version="1.1.0", org.osgi.service.url; version="1.0.0", org.osgi.util.tracker; version="1.5.0"
Export-Service = org.osgi.service.packageadmin.PackageAdmin,org.osgi.service.startlevel.StartLevel,org.osgi.service.url.URLHandlers
Provide-Capability =
这与普通系统包的系统包导出没有什么不同 ;-) 不知道有没有作用:我是这样启动Felix的:
Properties configArg = new Properties();
File chacheDir = this.getFilesDir();
configArg.setProperty(Constants.FRAMEWORK_STORAGE, chacheDir.getAbsolutePath());
configArg.setProperty("osgi.shell.telnet.ip", ipadd);
configArg.setProperty("osgi.shell.telnet.port", "6666");
Felix felix = new Felix(configArg);
try{
felix.start();
...
现在的问题是,如何在系统包中获取缺失的标准 java 包。
最佳答案
我找到的最佳解决方案是将 FRAMEWORK_SYSTEMPACKAGES
替换为 Android 平台中可用的特定包。这些是,
- 您在目标设备的
android.jar
中找到的所有包, - 除了
java.*
和junit.*
, - 但系统 bundle 的所有
org.osgi.*
包都可以正常导出。
所以,像
String SYSTEM_PACKAGES =
"org.osgi.framework;version=\"1.6\"," +
// ...
"android," +
// ...
"javax.crypto," +
// ...
"org.apache.commons.logging";
Map<String, Object> config = new HashMap<String, Object>();
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES, SYSTEM_PACKAGES);
Framework framework = new Felix(config);
framework.start();
关于android - OSGi(费利克斯): Change standard packages of system bundle to make it run on Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947678/