从 Android 项目调用本机方法
我正在创建一个尝试注入触摸事件的应用程序,这需要事件时间。当我调用 SystemClock.uptimeMillis() 来获取时间时,出现运行时错误。我认为问题是由于 uptimeMillis() 是本机方法这一事实引起的。运行时抛出的错误是 UnsatisfiedLinkError。
android jar 文件包含在项目中,允许编译而不会出现任何错误。我认为问题在于 java 包装器 (SystemClock.java) 在项目中可用。但是,在运行时无法找到 C 中的本机方法(来自文件 android_os_SystemClock.cpp)。关于在构建我的项目时如何包含本机方法(java 包装器所需)有什么想法吗?
多谢!
I'm creating an app that tries to inject a touch event, which requires the event time. When I call SystemClock.uptimeMillis() to get the time, there is a run time error. I think the problem arises from the fact that uptimeMillis() is a native method. The error thrown during runtime is an UnsatisfiedLinkError.
The android jar file is included in the project, allowing for compilation without any errors. I think the problem is that the java wrapper (SystemClock.java) is available in the project. However, the native method in C (from file android_os_SystemClock.cpp) cannot be found during run time. Any ideas on how to include the native methods (required by the java wrappers) when building my project?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 NDK 项目导入到 Eclipse SDK 项目中。在您的项目上右键单击并选择 -> Android 工具 ->添加本机支持 ->单击“完成”。
这会将您的本机项目文件拉至 Eclipse。现在您必须实现几个示例项目中给出的功能。
You can import an NDK project in to your Eclipse SDK project. On your project do a right-click and chose -> Android Tools -> Add Native Support -> Click Finish.
This will pull your native project files to Eclipse. Now you have to implement the functions as given in several sample projects.