使用Android API的OSGI Bundle显示“java.lang.RuntimeException:Stub!at android.util.Log.d”

时间:2013-08-12 17:36:15

标签: android osgi logcat android-logcat osgi-bundle

在我的eclipse插件项目中,我正在尝试使用Android API。我只在LogCat上显示一条消息。

除了将Android.jar添加到我的课程路径之外,我还通过this链接准备了Android.jar作为一个包。所以我做了以下事情:

1-编写包含以下内容的MANIFEST.txt:

Manifest-Version: 1.0
Created-By: myself
Bundle-ManifestVersion: 2
Bundle-Name: android
Bundle-Description: Package android in an OSGi bundle
Bundle-Version: 4.4.0
Bundle-ClassPath: .,android.jar
Bundle-SymbolicName: android
Export-Package: android.util

2-运行以下命令创建bundle jar文件:

jar cvfm android-bundle.jar manifest.txt android.jar 

3-现在我有了捆绑android-bundle.jar,我在File-> New -> Project...-> Plug-in Development -> "Plug-in from Existing JAR Archives"

的日食中打开它

接下来,我创建将使用android API的包。下面是Activator类,它有一条Log消息:

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用于使用Android API的包:

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

当我运行此捆绑包时,我会在Log上打印消息的行中收到这些错误。

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.RuntimeException: Stub!
    at android.util.Log.d(Log.java:7)
    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
Root exception:
java.lang.RuntimeException: Stub!
    at android.util.Log.d(Log.java:7)
    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)

!ENTRY OSGI_Android_Bundle 4 0 2013-08-12 21:34:21.528
!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.setBundleSL(StartLevelManager.java:670)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:435)
    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.RuntimeException: Stub!
    at android.util.Log.d(Log.java:7)
    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)
    ... 9 more
Root exception:
java.lang.RuntimeException: Stub!
    at android.util.Log.d(Log.java:7)
    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.setBundleSL(StartLevelManager.java:670)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:435)
    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)

1 个答案:

答案 0 :(得分:0)

android.util.Log的这个副本似乎在说它只是一个存根,而不是一个真正的实现。可能它纯粹是为了编译而创建的,并且预计不会在运行时使用。

<强>更新: 以下stackoverflow问题似乎证实了我的猜测:Error java.lang.RuntimeException: Stub! in Android with Fitnesse testing

你真的在Android设备或模拟器上运行吗?您似乎可能正在运行标准JVM。