1

在我的 Eclipse 插件项目中,我正在尝试使用 Android API。

我做的第一件事是添加Android.jar到构建路径。然后,我尝试在控制台(使用System.out.println())和 LogCat(使用android/util.Log)上显示一条消息。我在我start()的 Bundle Activator 类的方法中显示这些消息。

我还在我的文件中导出和导入了android.util包。MANIFEST.MF

当我运行捆绑包时,我在控制台上看到第一条消息,但在那之后,我收到以下错误:

!ENTRY OSGI_Android_Bundle 4 0 2013-08-11 07:54:56.008
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Exception in osgi_android_bundle.Activator.start() of bundle OSGI_Android_Bundle.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.NoClassDefFoundError: android/util/Log
    at osgi_android_bundle.Activator.start(Activator.java:27)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: android.util.Log
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 16 more
Root exception:
java.lang.NoClassDefFoundError: android/util/Log
    at osgi_android_bundle.Activator.start(Activator.java:27)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.ClassNotFoundException: android.util.Log
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 16 more

我试图寻找类似的情况,但我发现它们没有得到答复。例如这里在stackoveflow。

有人可以帮忙吗?下面是我的代码:

package osgi_android_bundle;

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


import android.util.Log;

public class Activator implements BundleActivator {

    private static BundleContext context;

    static BundleContext getContext() {
        return context;
    }

    /*
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(BundleContext bundleContext) throws Exception {
        Activator.context = bundleContext;


        System.out.println("Hello World. I am the OSGI_Android_Bundle!");

        Log.d("Zaid Log", "Hello World. I am the OSGI_Android_Bundle!!");
    }

    /*
     * (non-Javadoc)
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(BundleContext bundleContext) throws Exception {
        Activator.context = null;


        System.out.println("Goodbye World. I am the OSGI_Android_Bundle!");

        Log.d("Zaid Log", "Goodbye World. I am the OSGI_Android_Bundle!!");
    }

}

还有我的 MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OSGI_Android_Bundle
Bundle-SymbolicName: OSGI_Android_Bundle
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: osgi_android_bundle.Activator
Import-Package: org.osgi.framework;version="1.3.0", android.util
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: android.util

注意:当我在我的 Android 应用程序(嵌入了 Knopflerfish 平台)中启动这个包时,它根本不显示任何东西。所以我想我应该先修复上述错误,以便在日志中看到消息。

4

2 回答 2

0

您可以参考我的主题中的“启用非图形android bundle”一章。即使它是针对 Knopflerfish 的,只要您可以修改它,这些更改也应该适用于另一个 OSGi 实现。

对 OSGi 捆绑包的完整 Android 支持

同时,我不介意对我的主题有所帮助。

于 2013-09-03T09:34:19.717 回答
0

我不熟悉 andriod,但我可以从 OSGi 的角度发表评论。你导出 android.util 是不正确的,因为你的包没有那个类。

相反,您需要将 android.jar 准备为另一个 OSGi 包,因为该 jar 确实具有该包并将其添加到 OSGi 运行时。将其添加到构建路径是不够的。

于 2013-08-11T15:21:19.143 回答