我可以在一个独立的项目中使用android.os。*库? [英] Can I use android.os.* libraries in a standalone project?

查看:233
本文介绍了我可以在一个独立的项目中使用android.os。*库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立外部库(不知道这是正确的术语)来提供prepackaged功能在Android中的项目。工作在Eclipse中,我已经添加了相应的android.jar文件添加到构建路径,一切都是幸福的,而这两个编辑和编译时。

然而,当我使用Android的处理器和消息类(android.os.Handler,android.os.Message)线程间的通信,我得到的,除非我在一个Android应用程序运行时,在模拟器上或例外设备。我可以不必再通过运行Android的目标不再是测试我的库中的一个独立的方式。

有没有办法对我来说,包括这两款Android类,仍然能够测试我的图书馆的独立?我需要有可用的Andr​​oid源?还是会需要某种条件编译的挥手?

解决方案
  

有没有办法对我来说,包括   这两个机器人类,仍然是   能够测试我的图书馆独立?

不容易,以任何方式我能想到的。

  

我是否需要有Android源   是否可用?

我不知道你还有什么地方得到实施。但是,更重要的是,这些事情并没有设计独立工作的操作系统之外,任何比你更可以只抓住一个或两个可可类,并将其拉入您的Objective-C库,并期望他们在Windows中运行。

即兴,知道任何关于你正在建立,我会做任何依赖你介绍关于处理程序,什么消息更可插拔。 Android系统采用纯Java实现,甚至只是一些模拟考试测试之外。测试使用的是Android真正实施的内部。

I'm trying to develop an external library (not sure if that's the right term) to provide prepackaged functionality in Android projects. Working in Eclipse, I've added the appropriate android.jar file to the build path, and everything is happy both while editing and upon compilation.

However, when I use Android's Handler and Message classes (android.os.Handler, android.os.Message) for inter-thread communication, I get exceptions unless I'm running within an Android app, on the emulator or a device. I can no longer test my library in a "standalone" way without having to go through a running Android target.

Is there any way for me to include these two Android classes and still be able to test my library standalone? Do I need to have the Android source available? Or would it require some sort of conditional compilation hand-waving?

解决方案

Is there any way for me to include these two Android classes and still be able to test my library standalone?

Not readily, by any means I can think of.

Do I need to have the Android source available?

I don't know where else you would get the implementation from. But, more importantly, those things are not designed to work in isolation outside of the OS, any more than you could just grab a Cocoa class or two and pull them into your Objective-C library and expect them to run on a Windows box.

Off the cuff, knowing nothing about what you're building, I would make whatever dependency you are introducing on Handler and Message be more pluggable. Test outside of Android using a pure-Java implementation, perhaps even just some mocks. Test inside of Android using the real implementation.

这篇关于我可以在一个独立的项目中使用android.os。*库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆