简体   繁体   中英

Create and run an android project without a device or emulator

I'm trying to create a new Eclipse Project where I can test android classes without having to start the emu or connect a device.

I imported the android libraries, but I can't get it to work... My project only contains one java file where I use an android class, I only want to start it as a simple java app.

The error I get is: "Exception in thread "main" java.lang.RuntimeException: Stub!"

My question is: How can I create a simple java project (in eclipse) which uses android classes?

My question is: How can I create a simple java project (in eclipse) which uses android classes?

You can't.

There are no "android classes". Android is an operating system, not a class library. The real "Android classes" exist only in the operating system, either on an emulator or a device. The android.jar file is merely a set of stubs that allows the Java build tools to successfully compile Android applications.

If you have Java code that has no Android dependencies, you can build that in a regular Java project, perhaps creating a JAR file that your Android project then uses.

If your goal is to unit test classes within your Android app, then you should look at creating an Android test project. See Hello, Testing for a step by step guide in setting this up.

有一个android模拟器可以在开发机器上本地运行应用程序,但是它不像模拟器那样健壮或维护得很好,通常只用于非常狭窄的高级任务,这些头疼使运行变得很头疼补充配置文件工具。

Yes you can...

You must use robolectric see documentation here

Yo can find user-guide here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM