Skip to content Skip to sidebar Skip to footer

Running Tests Using Gradle Or Inside Android Studio Result In Noclassdeffounderror

I know that asking this type of question without specifics is very difficult, however; the project that is having the problem is proprietary and I have not been able to reproduce t

Solution 1:

Okay so I was able to solve this problem based on a number of references. First thanks to yogurtearl for all you information. In essence there were a number of issues. In the end though the NoClassDefError was a red herring. The real issue was in the logcat output posted after the initial question. The indicated that there were issues trying to resolve thing after pre-dexing.

So I highly recommend people run the command gradle -q dependencies. Running this will give you a wealth of information. Based on that output I was able to determine that I was not excluding things so multiple versions were included creating an issue at runtime. The other thing that was incorrect initially was that I had exclude group: 'com.square.dagger' which was a typo. It should have been exclude group: 'com.squareup.dagger'. I hope that someone comes across this and it saves them some time trying to track down the issues. The following article was very useful in solving this issue: http://blog.gaku.net/multiple-dex-files-define-with-gradle/

Solution 2:

Solutions:

  1. Change the dependency for fest-android to version 1.0.7

    androidTestCompile 'com.squareup:fest-android:1.0.7'

  2. Exclude support-v4 from fest-android:

    androidTestCompile ( 'com.squareup:fest-android:1.0.+' ) { exclude group:'com.android.support', module:'support-v4' }

  3. Upgrade to AssertJ-Android ( recommended ). Fest-Android has been superseded by AssertJ-Android ( http://square.github.io/assertj-android/ )

    androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'

Background info:

The problem is that "com.squareup:fest-android:1.0.+" is resolving to com.squareup:fest-android:1.0.8.

Version 1.0.8 includes a gradle dependency on 'com.android.support:support-v4:19.1.+'. See here: https://github.com/square/assertj-android/blob/1.0.8/build.gradle

This was translated to a "compile" scope dependency on support-v4 in the maven pom. See here: http://repo1.maven.org/maven2/com/squareup/fest-android/1.0.8/fest-android-1.0.8.pom

BTW, version 1.0.7 was built with Maven ( not gradle ) and has a "provided" scope dependency for support-v4, so that is why that behaves differently. See here: http://repo1.maven.org/maven2/com/squareup/fest-android/1.0.7/fest-android-1.0.7.pom

Also, Android Lint issues warnings for "Gradle Dynamic Version".

"Using + in dependencies lets you automatically pick up the latest available version rather than a specific, named version. However, this is not recommended; your builds are not repeatable; you may have tested with a slightly different version than what the build server used."

In this case, using a '+' for fest-android would have caused your build to break without any change on your part, when fest-android v1.0.8 was released.

Solution 3:

I had a similar problem and I ended up figuring out that I was running up against the limitations of the multidex support library which I was using to get over Android's 65K method limit. There isn't really a good solution for that other than to try to rip out unused libs from your project, use proguard, or set your minSdkVersion to 21. Hopefully this helps anyone who ends up here facing a similar issue.

Post a Comment for "Running Tests Using Gradle Or Inside Android Studio Result In Noclassdeffounderror"