Why do I get a NoClassDefFoundError when running my test on an ActionBarActivity?
Asked Answered
R

3

8

So I am using Robotium and my test class is extending the ActivityInstrumentationTestCase2 class. I have imported the v7 support library in my main project and also in the test project as libraries.

Now what I don't understand is that the test class is working when I change the class under test to extend Activity but when I change it to ActionBarActivity it returns a NoClassDefFoundError.

Am I missing anything?

Here is the Log I am getting

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>
Redness answered 9/4, 2015 at 10:11 Comment(12)
Did you see this?Encephalography
Why use Robotium? Use the new Espresso that is supported by Google. Post your code as well.Loiseloiter
Sorry, robotium is the current one we have been using in the company for a long time and it is used in our TDD workflow so migrating to Espresso isn't an optionRedness
I am guessing you are also using Eclipse as well? Can you post more information as well as the code?Loiseloiter
2 questions so i could see if my idea fits: Are you using proguard? Are you using gradle?Dubrovnik
No proguaes and no gradleRedness
@JohnErnestGuadalupe Can you answer my comment?Loiseloiter
@Jared Burrows. I already did " Sorry, robotium is the current one we have been using in the company for a long time and it is used in our TDD workflow so migrating to Espresso isn't an option "Redness
@JohnErnestGuadalupe I said I am guessing you are also using Eclipse as well? Can you post more information as well as the code? .Loiseloiter
@JohnErnestGuadalupe post some codeAmbages
the class "com.example.project.ActivityClass" is missing in you apk file. based on the package i guess it is your class. so why should it be missing if you change their dependency that should not have anything to do with your class: the new dependency can not be found on compile?Housecarl
and if this is not obvius, it happens while/before constructor call of the test class but the class under test is missing.Housecarl
Y
4

Ensure you export the v7 support library referenced in test project.

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

For an example see step 5 under "Setup" Section here: http://www.stevenmarkford.com/android-ui-testing-with-espresso-basics-tutorial/ (although this is showing how to export the espresso library the same would apply in this case)

Yettie answered 17/4, 2015 at 7:47 Comment(0)
G
2

I think your library v7 app compat has an import problem.

Try this:

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

  • 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 your main project gen folder.

If it still doesn't solve your problem, restart eclipse and clean and rebuild project

If the problem persists, remove the support library from you computer and redownload it and follow above mentioned steps.

Grith answered 14/4, 2015 at 7:57 Comment(3)
Do you have a working unit test for actionbaractivity?Redness
At this moment I cannot retrieve my own code but you can find a lot of examples on internet. Did you try what i said above ?Grith
Link to actual example? You know, I won't be able to use the ActionBarActivity if I did not already do that.Redness
B
0

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

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

More here.

Baillieu answered 17/4, 2015 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.