DONN FELKER

Lessons Learned From the Software Industry

  • Home
  • About
  • Caster.IO
  • Fragmented Podcast
  • A Newsletter For Maximizing Your Life
  • Contact

Connect

  • GitHub
  • Instagram
  • LinkedIn
  • RSS
  • Twitter

Powered by Genesis

Android Studio Espresso 2.0 ClassNotFoundException

January 13, 2015 by Donn Felker 9 Comments

File this under “I’m writing this so when I Google for it in 6 months, it pops up”. 

 

I recently set up an existing Android project with Espresso 2.0 and immediately stared running into this error when I ran the tests: 

Running tests
Test running started
Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
Empty test suite.

I spent some time last night fighting this error and then I figured out the solution this morning.

The problem is that I’m using Dagger in this project and Espresso 2.0 also uses Dagger (see Espresso Dependencies). The core problem is that the ‘javax.inject’ dependency was borking the test run. 

How to to Fix

Change this

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')

to this: 

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
   exclude group: 'javax.inject'
}

 

Problem solved. 

Filed Under: Development, Mobile Tagged With: Android

Get posts like this in your inbox.

Everything I share on my site will get sent out to my email newsletter first. This includes new articles, any things I’m working on, early access and discounts to products/books/ebooks and more. If you want it early, hop on the list below.

What kind of stuff am I going to be sharing?

A lot about how to start consulting, working for yourself, productivity, discipline, hard work, fitness, and more. I look forward to chatting with you via email.

Comments

  1. Bryant says

    January 19, 2015 at 6:37 pm

    Thank you!

  2. Mark OBrien says

    January 25, 2015 at 2:58 pm

    Just saved me a night of trying to figure this out. Tests running now. Thanks

  3. Donn Felker says

    March 3, 2015 at 1:02 pm

    No problem. 🙂 Glad it helped.

  4. Donn Felker says

    March 3, 2015 at 1:03 pm

    NP!

  5. Brian says

    January 8, 2016 at 12:20 am

    actually, i want to know the way you find the problem

  6. Sharma Hitesh says

    April 2, 2016 at 5:11 am

    Even after excluding java.inject in manifest file, i am still facing this issue. Getting following error now “Execution failed for task ‘:dexArmDebugAndroidTest’.

    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java” finished with non-zero exit value 1″

  7. Stas Shakirov says

    May 30, 2016 at 7:09 am

    Not helped for me.
    “`

    ext {
    junitVersion = ‘4.12’
    hamcrestVersion = ‘1.3’
    runnerVersion = ‘0.5’
    rulesVersion = ‘0.5’
    espressoVersion = ‘2.2.2’
    googlePlayServiceVersion = “8.4.0”
    supportVersion = “23.4.0”
    }
    “`

  8. ChunLun Kuo says

    August 2, 2016 at 3:42 am

    You save me a week ! Thanks!!!!!!!!!!!!!!!!!!

  9. vishal says

    November 10, 2016 at 2:46 am

    Hi I have tried this but still get same issue
    below are my gradle
    dependencies {
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
    compile ‘com.android.support:recyclerview-v7:23.1.1’
    compile ‘com.android.support:appcompat-v7:23.1.1’
    compile ‘com.android.volley:volley:1.+’
    compile “com.squareup.picasso:picasso:2.4.0”
    compile ‘com.android.support:multidex:1.0.0’
    testCompile ‘junit:junit:4.12’

    // Android runner and rules support
    androidTestCompile ‘com.android.support.test:runner:0.5’
    androidTestCompile ‘com.android.support.test:rules:0.5’

    // Espresso support
    androidTestCompile (‘com.android.support.test.espresso:espresso-contrib:2.2’){
    exclude group: ‘com.android.support’, module: ‘appcompat-v7’
    exclude group: ‘com.android.support’, module: ‘support-v4’
    exclude module: ‘recyclerview-v7’
    exclude group: “javax.inject”
    exclude group: ‘com.google.guava’
    }

    androidTestCompile(‘com.android.support:multidex-instrumentation:1.0.1’) {
    exclude group: ‘com.android.support’, module: ‘multidex’
    }
    // add this for intent mocking support
    androidTestCompile ‘com.android.support.test.espresso:espresso-intents:2.2.2’

    // add this for webview testing support
    androidTestCompile ‘com.android.support.test.espresso:espresso-web:2.2.2’

    androidTestCompile ‘com.android.support.test.espresso:espresso-contrib:2.2.2’

    }

    and want to move from splash to navigation drawer but not recognize my navigation activity and give java.lang.NoClassDefFoundError: please help

Leave a Reply Cancel reply

You must be logged in to post a comment.

Fragmented - A Software Developer Podcast

Projects / Apps

Caster.IO
Fragmented Podcast
American Express Android
Aaptiv
AndroidJobs.IO
Groupon
MyFitnessPal
Poynt

Books

  • Android Developer Tools
  • Android App Dev For Dummies V2 (V1)
  • Android Tablet App Dev for Dummies

Categories

  • Book
  • Business
  • Development
  • Health
  • Marketing
  • Misc
  • Mobile
  • Podcast
  • Screencasts
  • Uncategorized