Robolectric+Eclipse Can't find resources?

ε祈祈猫儿з 提交于 2019-12-04 02:39:12

I had to add an environment variable to my test run configuration:

ANDROID_HOME=C:/path/to/android-sdks

I had the exact same issue (RuntimeException when loading the resources) when first setting up my Eclipse project with Robolectric but now it works.

I figured two things out:

  • If you receive a WARNING: Unable to find path to Android SDK (the message might not be displayed in a version lower than 1.0-RC1) then ResourceLoader failed to find your SDK root. One of the methods looks for an ANDROID_HOME environment variable that should point to where your Android SDK resides.
  • Finally, there is a bug which causes an exception if your menu.xml is not formatted in a certain way.

Using Robolectric without Maven or Ant is possible but there might be a few more bugs. This video shows the correct project setup. If it doesn't work, get the latest version from Github (import as a Maven project in Eclipse and you might need github.com/mosabua/maven-android-sdk-deployer) and start debugging!

If the ResourceNotFound only occurs for string arrays defined with <array>...</array> tags, replace them with <string-array>...</string-array>

Using robolectric 2.0

read in: https://groups.google.com/forum/#!topic/robolectric/gQoY0bCguYs

docs: http://developer.android.com/guide/topics/resources/string-resource.html#StringArray

Its wrong obviously..I had to setup an ant way to do things as you cannot launch robolectric tests from eclipse as the Eclipse workspace still does not recognize linked-source individual files properly..see my alpha example:

https://github.com/shareme/Wabash

Same error that I get by the way..from the Pivotal Labs directions..

jstewart379

Just had this problem after doing a fresh install of Windows 8. Most likely Robolectric cannot find the SDK. In order to point it to the right place. You can generate a local.properties file in your Android project. This can be done in the command line by going to the root folder of your project and issuing the command:

android update project –p c:\project\root\folder

Open local.properties to verify the sdk.dir is pointing to the expected path.

Also make sure you have downloaded android API level 8. Robolectric looks for a folder in the /path/to/your/sdk/platforms/android-8 directory.

You can get the Jar file in this link.just download it. add JAR in project thats it.i have used in my project. Any doubts ask me

http://www.java2s.com/Code/JarDownload/robolectric/robolectric-1.2-8.jar.zip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!