Why am I getting a NoClassDefFoundError when I run my test in an ActionBarActivity?

So, I use Robotium, and my test class extends the ActivityInstrumentationTestCase2 class. I imported the v7 support library in my main project, as well as in the test project as libraries.

Now I don’t understand that the test class works when I change the test class to extend the Activity , but when I change it to ActionBarActivity , it returns a NoClassDefFoundError .

Did I miss something?

Here is the magazine I get

 04-11 21:32:16.551: E/dalvikvm(23925): Could not find class 'com.example.project.ActivityClass', referenced from method com.example.project.tests.ActivityClass.<init> 
+8
java android unit-testing robotium android-actionbaractivity
source share
3 answers

Make sure you export the v7 support library specified in the test project.

Right click on the test project, properties-> java build path-> order and export tab.

For an example, see step 5 in the Setup section here: http://www.stevenmarkford.com/android-ui-testing-with-espresso-basics-tutorial/ (although this shows how to export an espresso library, the same applicable in this case as well)

+4
source share

I think your v7 app compat library has a problem with import.

Try the following:

  • Import the support library as a project from "sdk/extras/android/support/v7/appcompat".

  • The reference library in your project (for Eclipse, "Properties - Android - Add" ).

  • Build projects (for Eclipse, "Projects - Build All" ). Make sure you have "android.support.v7.appcompat" in the folder of the main project directory.

If it still does not solve your problem, restart eclipse and clean and rebuild the project

If the problem persists, remove the support library from your computer and restart it and follow the steps above.

+2
source share

This code in build.gradle solved a similar problem for me:

 configurations { androidTestCompile.exclude group: 'com.android.support', module: 'support-v4' } 

More details here .

0
source share

All Articles