Using android.jar in Java project - RuntimeException Stub?

前端 未结 2 728
Happy的楠姐
Happy的楠姐 2020-12-11 03:03

I tried to include android.jar into Java project, remove JRE from Build Path and run this code. It throws Runtime exception. Why?



        
2条回答
  •  北海茫月
    2020-12-11 03:17

    android.jar contains stubs only, enough to let you build your project, as @antlersoft explained.

    The Robolectric project http://robolectric.org/ allows you to run tests on your Android code without using a device. They have real builds available on Maven http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.robolectric%22

    I have been successfully running most of the Android backend code by using the android-all artifact.

    Might not help in your specific case, since some APIs are still out of bounds, but for most other cases of java.lang.RuntimeException: Stub! including the artifacts from Robolectric should help.

提交回复
热议问题