Torsten
Torsten

Reputation: 752

Runtime Exception running robolectric tests IntelliJ

When running my robolectric tests in IntelliJ I get:

Warning: an error occurred while binding shadow class: ShadowGeoPoint
Warning: an error occurred while binding shadow class: ShadowItemizedOverlay
Warning: an error occurred while binding shadow class: ShadowMapController
Warning: an error occurred while binding shadow class: ShadowMapActivity
Warning: an error occurred while binding shadow class: ShadowMapView
Warning: an error occurred while binding shadow class: ShadowOverlayItem
WARNING: Unable to find path to Android SDK

java.lang.RuntimeException: java.lang.NullPointerException
    at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:158)
    at com.xtremelabs.robolectric.res.ResourceLoader.setLayoutQualifierSearchPath(ResourceLoader.java:599)
    at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:367)
    at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:311)
    at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:278)
    at ...

The ANDROID_HOME ist set but InteliJ does not seem to find it.

Upvotes: 1

Views: 921

Answers (2)

Karthik Chandraraj
Karthik Chandraraj

Reputation: 1041

  • Go to Run Configurations (Run -> EditConfigurations..)
  • Select your test from the left hand side (under JUnit)
  • In the configurations tab, go to Environment Variables section and add an environment variable ANDROID_HOME pointing to your sdk
  • Apply, build and run the test again

Note : You can add this in the JUnit default settings, so that you don't have to do for each test class

Upvotes: 0

Sam R.
Sam R.

Reputation: 16450

Set the sdk.dir in a local.properties file by running the following in your project’s root dir:

$ android update project -p .

Setting up a local.properties file is a solution that will work for most IDEs since you don’t need to worry about getting environment variables passed around.

I got this from Unable to find Android SDK. There are also few other options which you may try.

Upvotes: 2

Related Questions