Search code examples
androidosgilogcatandroid-logcatosgi-bundle

OSGI Bundle using Android API is showing "java.lang.RuntimeException: Stub! at android.util.Log.d"


In my eclipse plugin project, I am trying to use the Android API. I am only showing a message on the LogCat.

In addition to adding Android.jar to my class path, I prepared Android.jar as a bundle by follwing this link. So I did the following:

1- Writing the MANIFEST.txt which contains the following:

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- Creating the bundle jar file by running the following command:

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

3- Now that I have the bundle android-bundle.jar, I open it in eclipse by File-> New -> Project...-> Plug-in Development -> "Plug-in from Existing JAR Archives"

Next, I create the bundle that will use the android API. Below is the Activator class which has a Log message:

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!!");
    }

}

And also my MANIFEST.MF for the bundle which uses the 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

When I run this bundle, I get these errors at the line that prints the message on the 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)

Solution

  • This copy of android.util.Log appears to be saying that's it's only a stub, rather than a real implementation. Probably it was created purely for compiling against, and is not expected to be used at runtime.

    UPDATE: The following stackoverflow question appears to confirm my guess: Error java.lang.RuntimeException: Stub! in Android with Fitnesse testing

    Are you actually running on an Android device or emulator?? It seems you may be running on the standard JVM.