问题描述
在我的Eclipse插件的项目,我想使用Android API。我只是表现出对LogCat中的消息。
在除了添加的android.jar
我的类路径,我prepared 的android.jar
作为通过follwing 链接捆绑。所以,我做了以下内容:
1-写入其中包含以下的MANIFEST.txt:
清单-版本:1.0
创建-人:我自己
束ManifestVersion:2
束名称:Android
束描述:OSGi包包装机器人
束版本:4.4.0
束CLASSPATH中,的android.jar
束SymbolicName:机器人
出口包装:android.util
2 - 创建通过运行以下命令包jar文件:
罐子CVFM Android的bundle.jar manifest.txt的android.jar
3现在,我有包 Android的bundle.jar
,我通过文件&GT在Eclipse中打开它;新 - >项目...->插件开发 - > 插件从现有JAR档案
接下来,我创建将采用Android API包。下面是其中有一个日志消息Activator类:
包osgi_android_bundle;进口org.osgi.framework.BundleActivator;
进口org.osgi.framework.BundleContext;
进口android.util.Log;公共类激活实现BundleActivator的{ 私有静态的BundleContext上下文 静态的BundleContext的getContext(){
返回语境;
} / *
*(非Javadoc中)
* @see org.osgi.framework.BundleActivator#启动(org.osgi.framework.BundleContext)
* /
公共无效启动(BundleContext的的BundleContext)抛出异常{
Activator.context =的BundleContext;
的System.out.println(世界您好我是OSGI_Android_Bundle!); Log.d(扎伊德日志,世界您好我是OSGI_Android_Bundle!);
} / *
*(非Javadoc中)
* @see org.osgi.framework.BundleActivator#停止(org.osgi.framework.BundleContext)
* /
公共无效停止(BundleContext的的BundleContext)抛出异常{
Activator.context = NULL;
的System.out.println(再见,世界,我的OSGI_Android_Bundle!); Log.d(扎伊德日志,再见,世界,我的OSGI_Android_Bundle!);
}}
也是我的MANIFEST.MF为其采用了Android API包:
清单-版本:1.0
束ManifestVersion:2
束名称:OSGI_Android_Bundle
束SymbolicName:OSGI_Android_Bundle
束版本:1.0.0.qualifier
束激活:osgi_android_bundle.Activator
进口包装:org.osgi.framework;版本=1.3.0,android.util
束RequiredExecutionEnvironment:JavaSE的-1.6
当我运行这个包,我得到一个打印的日志。
消息的行这些错误 org.osgi.framework.BundleException:异常的osgi_android_bundle.Activator.start()捆绑OSGI_Android_Bundle的。
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
在org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
在org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
在org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
在org.eclipse.osgi.framework.eventmgr.EventManager $ EventThread.run(EventManager.java:340)
了java.lang.RuntimeException:存根造成的!
在android.util.Log.d(Log.java:7)
在osgi_android_bundle.Activator.start(Activator.java:27)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl $ 1.run(BundleContextImpl.java:711)
在java.security.AccessController.doPrivileged(本机方法)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 12更多
根异常:
了java.lang.RuntimeException:存根!
在android.util.Log.d(Log.java:7)
在osgi_android_bundle.Activator.start(Activator.java:27)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl $ 1.run(BundleContextImpl.java:711)
在java.security.AccessController.doPrivileged(本机方法)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
在org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
在org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
在org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
在org.eclipse.osgi.framework.eventmgr.EventManager $ EventThread.run(EventManager.java:340)!ENTRY OSGI_Android_Bundle 4 0 2013年8月12日21:34:21.528
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException:异常的osgi_android_bundle.Activator.start()捆绑OSGI_Android_Bundle的。
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
在org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
在org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.setBundleSL(StartLevelManager.java:670)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:435)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
在org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
在org.eclipse.osgi.framework.eventmgr.EventManager $ EventThread.run(EventManager.java:340)
了java.lang.RuntimeException:存根造成的!
在android.util.Log.d(Log.java:7)
在osgi_android_bundle.Activator.start(Activator.java:27)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl $ 1.run(BundleContextImpl.java:711)
在java.security.AccessController.doPrivileged(本机方法)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 9个
根异常:
了java.lang.RuntimeException:存根!
在android.util.Log.d(Log.java:7)
在osgi_android_bundle.Activator.start(Activator.java:27)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl $ 1.run(BundleContextImpl.java:711)
在java.security.AccessController.doPrivileged(本机方法)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
在org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
在org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
在org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.setBundleSL(StartLevelManager.java:670)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:435)
在org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
在org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
在org.eclipse.osgi.framework.eventmgr.EventManager $ EventThread.run(EventManager.java:340)
此副本 android.util.Log
似乎是说,是它只是一个存根,而不是一个真正的实现。可能有人纯粹创建用于编译反对,预计不会在运行时被使用。
更新:
下面的计算器问题似乎证实了我的猜测:Error了java.lang.RuntimeException:存根!在Android中使用FitNesse的测试
您实际上是一个Android设备或模拟器上运行?看来你可以在标准JVM上运行。
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)
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.
这篇关于OSGI包采用Android API正显示出"了java.lang.RuntimeException:存根!在android.util.Log.d"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!