【问题标题】:OSGi - Activator can't access internal packages of the BundleOSGi - Activator 无法访问 Bundle 的内部包
【发布时间】:2012-06-05 18:48:31
【问题描述】:

我正在尝试在 Apache Felix 上运行一个基于 EMF 的小型应用程序。 Felix 在 Android 设备上运行。我正在使用 Eclipse,但没有 bnd 和 maven。

我有一个 EMF Bundle,可以导出以下软件包:

org.eclipse.emf.common_droid-2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore_droid-2.7.0.v20120127-1122.jar
org.eclipse.emf.ecore.xmi_droid-2.7.0.v20120127-1122.jar

我的插件项目的结构:

[+] src
---> com.androidosgi.notifier
---> com.androidosgi.notifier.notification
---> com.androidosgi.notifier.notification.impl
---> com.androidosgi.notifier.notification.util
[+] META-INF
---> MANIFEST.MF
Notification-1.0.ecore
Notification-1.0.ecorediag
Notification-1.0.ecorert
NotificationComponent.xmi

激活器在 com.androidosgi.notifier 中。

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Notification Testing
Bundle-SymbolicName: com.androidosgi.notifier
Bundle-Version: 12.6.5
Bundle-Activator: com.androidosgi.notifier.Activator
Bundle-Vendor: Homer Simpson
Import-Package: 
 com.androidosgi.notifier.notification,
 com.androidosgi.notifier.notification.impl,
 com.androidosgi.notifier.notification.util,
 org.eclipse.emf.common,
 org.eclipse.emf.common.archive,
 org.eclipse.emf.common.command,
 org.eclipse.emf.common.notify,
 org.eclipse.emf.common.notify.impl,
 org.eclipse.emf.common.util,
 org.eclipse.emf.ecore,
 org.eclipse.emf.ecore.impl,
 org.eclipse.emf.ecore.plugin,
 org.eclipse.emf.ecore.resource,
 org.eclipse.emf.ecore.resource.impl,
 org.eclipse.emf.ecore.util,
 org.eclipse.emf.ecore.xmi,
 org.eclipse.emf.ecore.xmi.impl,
 org.eclipse.emf.ecore.xmi.util,
 org.eclipse.emf.ecore.xml.namespace,
 org.eclipse.emf.ecore.xml.namespace.impl,
 org.eclipse.emf.ecore.xml.namespace.util,
 org.eclipse.emf.ecore.xml.type,
 org.eclipse.emf.ecore.xml.type.impl,
 org.eclipse.emf.ecore.xml.type.internal,
 org.eclipse.emf.ecore.xml.type.util,
 org.osgi.framework;version="1.3.0"
Bundle-ClassPath: .
Export-Package: com.androidosgi.notifier;x-internal:=true,
 com.androidosgi.notifier.notification;x-internal:=true,
 com.androidosgi.notifier.notification.impl;x-internal:=true,
 com.androidosgi.notifier.notification.util;x-internal:=true

在 OSGi 上安装包之前,我将其“dexed”并将 classes.dex 添加到包中。

如果我尝试开始,我会得到:NoClassDefFoundError

有什么想法或解决方案吗? :) 谢谢

【问题讨论】:

  • 看看你的清单,为什么你的包导出了这么多它的内部包?你有异常的堆栈跟踪吗? EMF 是否使用反射来加载包的内部类?当你在 Android 之外运行时,你使用的是 Equinox 还是 Felix?
  • 内部包的导入只是为了让它发挥作用。在此之前,我有一个没有内部包且没有导出的版本。我不确定是否使用了 EMF 反射,但我认为是的。 Equinox,但现在我又变回了 felix。谢谢!

标签: android eclipse osgi noclassdeffounderror emf


【解决方案1】:

EMF 不会在 Felix 或除 Equinox 之外的任何 OSGi 框架上运行。请参阅我很久以前提出的以下错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=328227

您必须使用重新打包 EMF 以正确执行 OSGi 声明。我在 GitHub 上有这个,但现在有点陈旧,即它打包了旧版本的 EMF。见:https://github.com/njbartlett/emf-osgi

更新:我太仓促了,这可能不是正确的答案。看起来你已经重新打包了 EMF。

我怀疑答案是您正在导入包 com.androidosgi.notifier.notification 及其子包,但这些可能是您的包中的包。你不应该导入实际上是你的包的一部分的包。

【讨论】:

  • 感谢 Neil 的更新,重新打包的灵感来自您的 github repo ;) 但是我在使用 bnd 时遇到了一些问题,所以我按照自己的方式进行了操作。我从导入中删除了包。同样的问题:-((
【解决方案2】:

我想你已经检查了明显的事情: * 类 NotificationFactory 存在于包中 * 名称和路径没有错别字 * 该类不在内部 jar 或类似的东西中 * 激活器被系统成功找到? * 你试过删除导入吗?

我可以建议检查的唯一更奇怪的事情是问题是否不在于 NotificationFactory 本身,而在于它使用的某些类。我在其他设置中遇到过这样的情况,其中 ClassNotFound 实际上是针对报告类中的另一个类。

尝试例如移动 com.androidosgi.notifier.notification 包中的激活器 - 就像检查它是否会被找到。这样你就知道问题出在包还是类本身了。

【讨论】:

    【解决方案3】:

    Ok 50% 完成了 ;-) 它正在计算机上运行 (Java 1.6)(但仍然不在 Android 上)!在我的情况下,由于缺少版本控制内容而导致 NoClassDefFoundError 错误。我在导出的 EMF-Bundle(b1) 中的每个包中添加了版本。我还在导入的 Notifier-Bundle(b2) 中添加了每个包的版本范围。 看来,设置版本非常重要。 我也删除了:

    com.androidosgi.notifier.notification, com.androidosgi.notifier.notification.impl, com.androidosgi.notifier.notification.util,

    来自 Bundle(b2) 的导入和所有从 (b2) 的导出。 它现在在 Apache Felix 上运行。

    呃,我也加了

    进口包装: org.xml.sax.helpers;version="[0.0.0.1_006_JavaSE,3.0.0)"

    到 Bundle (b1) 的清单,EMF-Bundle。

    我的下一个问题是,android 中标准 systembundle 的导出似乎与普通计算机上的不同(使用命令“headers”查找)。我将为此开始一个新问题,并在此处发布链接。

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 2014-01-14
      • 2011-05-26
      • 2015-07-19
      • 2012-05-25
      • 1970-01-01
      相关资源
      最近更新 更多