Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: kotlin/test/AssertionsKt Error #130

Closed
laura-diana-prata opened this issue Jan 10, 2019 · 38 comments
Closed

Comments

@laura-diana-prata
Copy link

laura-diana-prata commented Jan 10, 2019

I have just added testImplementation 'org.amshove.kluent:kluent-android:1.45' to my Android project and when I run a simple test like this:

    @Test
    fun `this should be true`() {
            true.shouldBeTrue()
    }

the following error is thrown:

`java.lang.NoClassDefFoundError: kotlin/test/AssertionsKt

	at org.amshove.kluent.internal.AssertionsKt.assertTrue(Assertions.kt:7)
	at org.amshove.kluent.BasicKt.shouldBeTrue(Basic.kt:35)
	at ro.fortech.mindclub.validators.SimpleTest.this should be true(SimpleTest.kt:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: kotlin.test.AssertionsKt
@MarkusAmshove
Copy link
Owner

Hi @ziziana ,

can you give some more information?

I'm no Android expert and created a new app, added

testImplementation 'org.amshove.kluent:kluent-android:1.45'

to app/build.gradle and was able to run unittests from app/src/test.

When I add

androidTestImplementation 'org.amshove.kluent:kluent-android:1.45'

to app/build.gradle I'm able to run tests from app/src/androidTest.

@laura-diana-prata
Copy link
Author

laura-diana-prata commented Jan 10, 2019

I have just created a new project myself and I get the same error. I am using Android Studio 3.4. Preview. Kotlin version is 1.3.11.

app/build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "ro.sample.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.1.0-alpha03'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'org.amshove.kluent:kluent-android:1.45'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

screen shot 2019-01-10 at 4 29 51 pm

@MarkusAmshove
Copy link
Owner

Can you create a repository where you push the created project? I'm using a different Android Studio version and I'm curious if the generated Gradle files are different

@josh-burton
Copy link

I'm getting this same error on a few projects that use Studio 3.3 and Kotlin 1.3.x

@laura-diana-prata
Copy link
Author

laura-diana-prata commented Jan 11, 2019

@MarkusAmshove I pushed the project on my repo https://github.com/ziziana/repo

@MarkusAmshove
Copy link
Owner

Thank you, I'll try to replicate it with my current android studio version and then with 3.3

@laura-diana-prata
Copy link
Author

laura-diana-prata commented Jan 11, 2019

It seems that for my Android Studio version, the minimum supported Gradle version is 5.1-milestone-1 (this is in gradle-wrapper.properties). Could this be the problem?

@MarkusAmshove
Copy link
Owner

I get the following with Gradle 5.0:

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* Where:
Build file 'W:\android-issue\app\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Minimum supported Gradle version is 5.1-milestone-1. Current version is 5.0. If using the gradle wrapper, try editing the distributionUrl in W:\android-issue\gradle\wrapper\gradle-wrapper.properties to gradle-5.1-milestone-1-all.zip

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 43s

my guess by now is that it is actually Gradle 5.1 causing this.
The project that was created by Android Studio 3.2.1 used Gradle 4.6 as a wrapper and worked.

gradle/gradle/issues/8088 seems to be exactly this issue (and is pretty recent).

My guess is that the Android Studio Preview isn't ready yet, altough it is strange that a preview creates broken builds.

@MarkusAmshove
Copy link
Owner

To summarize:

  • Projects generated by Android Studio which target a Gradle version prior to 5.0 work
  • A project generated with Gradle 5.1 doesn't work with a previous Gradle version (see the Gradle error in my previous comment)
  • The POM does correctly state all dependencies, including kotlin.test:
<dependency>
  <groupId>org.jetbrains.kotlin</groupId>
  <artifactId>kotlin-test</artifactId>
  <version>1.3.10</version>
  <scope>runtime</scope>
</dependency>

I'm not sure where to open this issue.
It might be a good fit in the Android Studio bugtracker (is there any), as it seems to be a problem with the new version.
Otherwise it might be suitable in Gradle first.

@laura-diana-prata
Copy link
Author

laura-diana-prata commented Jan 11, 2019

OK, thank you very much for taking time to investigate this. Will you open an issue on their side (Android Studio or/and Gradle)? I would open it myself, but I am not sure how could I help them in case they will ask me for more details.

For Android Studio issues can be reported from Android Studio - Help - Submit Feedback

@MarkusAmshove
Copy link
Owner

I'm downloading Android Studio 3.3 at the moment and will report an issue :-)

@MarkusAmshove
Copy link
Owner

I'm not getting this problem with Studio 3.3, does it use Gradle 5 for you @athornz ?
It creates a proejct with Gradle 4.10 for me.

I'm download 3.4 now.

@MarkusAmshove
Copy link
Owner

I was able to reproduce it with 3.4 and opened an issue

@f2rf2r
Copy link

f2rf2r commented Jan 14, 2019

The issue is that Kluent includes older version (1.3.10) of some of the Kotlin libs as transitive dependencies, where as Android 3.3/3.4 only supports Kotlin 1.3.11+. This can be fixed by forcing those transitive dependencies to also use 1.3.11, i.e

testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.3.11"
testImplementation "org.jetbrains.kotlin:kotlin-test:1.3.11"

@MarkusAmshove
Copy link
Owner

Thank you for the hint, that's something I can fix on my end.
I find it strange that they rely on a minor version, but I guess that's fine.
Is this something they communicated or did you find it out somehow?

@f2rf2r
Copy link

f2rf2r commented Jan 14, 2019

They mentioned on the release note that AS 3.3 is bundled with Kotlin 1.3.11 https://android-developers.googleblog.com/2019/01/android-studio-33.html

@MarkusAmshove
Copy link
Owner

I'll update the kotlin version locally and see if I can use the artefact in Android

@MarkusAmshove
Copy link
Owner

MarkusAmshove commented Jan 15, 2019

I've updated to Kotlin 1.3.11 locally (in Kluent) and published a new version locally.

The resulting POM:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.amshove.kluent</groupId>
  <artifactId>kluent-android</artifactId>
  <version>1.47</version>
  <dependencies>
    <dependency>
      <groupId>org.amshove.kluent</groupId>
      <artifactId>kluent-common</artifactId>
      <version>1.47</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>1.3.11</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-reflect</artifactId>
      <version>1.3.11</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-test</artifactId>
      <version>1.3.11</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.nhaarman.mockitokotlin2</groupId>
      <artifactId>mockito-kotlin</artifactId>
      <version>2.0.0</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>

The tests still fail with the same error in AS 3.4.

The Gradle build runs fine though and the test passes.

@MarkusAmshove
Copy link
Owner

Creating a new project with AS 3.3 and targeting Kluent 1.46 (which uses Kotlin 1.3.10) does work, so I guess we're fine at the moment, as AS 3.3 is the new stable release?

I still opened the issue for 3.4 at Google.

@f2rf2r
Copy link

f2rf2r commented Jan 15, 2019

It looks like I got the underlying reason wrong, AS just doesn't pick up kotlin-test as transitive dependency regardless of the version. Adding testImplementation "org.jetbrains.kotlin:kotlin-test:1.3.11" to app build.gradle still works as a bandaid fix though.
I encountered this problem in both stable 3.3 and 3.4-alpha10.

@MarkusAmshove
Copy link
Owner

Which Gradle version does the project with 3.3 use?

@f2rf2r
Copy link

f2rf2r commented Jan 15, 2019

Android Gradle 3.3.0 and main Gradle 5.1.1. It runs fine on command line, just the issue with running it through AS.

@MarkusAmshove
Copy link
Owner

Yeah, I think this has to do with Gradle >= 5 and AS (or how AS handles Gradle), I think Google needs to sort that out

@AldrichMascarenhas
Copy link

Do we have an update wrt to this @MarkusAmshove

@MarkusAmshove
Copy link
Owner

I haven't heard back from Google yet, do you get this error on AS stable or on preview?

@josh-burton
Copy link

I'm not sure about stable, but I'm getting this on 3.4 beta03.

Adding the kotlin test dependency does fix the issue though.

@MarkusAmshove
Copy link
Owner

Oh, I think then it's related to the last conclusion in #133 and changing the dependency type might fix it.
Wondering if it is a problem in newer Gradle versions then

@MarkusAmshove
Copy link
Owner

Have you added org.jetbrains.kotlin:kotlin-test:$kotlin_version as testImplementation ?

@JotraN
Copy link

JotraN commented Feb 14, 2019

@MarkusAmshove, I'm experiencing this issue on the latest AS stable 3.3.1 (February 2019).

Adding in that kotlin test dependency worked though 🍾.

@MarkusAmshove
Copy link
Owner

Did you add it as testImplementation or test or testRuntime? :-)

Also I think then it's a Gradle issue rather than AS.
Are you using Gradle >= 5.0 by chance? (Either by wrapper or local installation)

@MarkusAmshove
Copy link
Owner

Can someone having that issue upload a newly generated android project to github, so I can test things out?
The build should fail when using gradlew.

@JotraN
Copy link

JotraN commented Feb 15, 2019

@MarkusAmshove, should've clarified, added it with testImplemenation.

I'm using gradle (wrapper) version 5.1.1 - running it from the command line (./gradlew test) always works for me (i.e. without needing to include the kotlin test dependency).

@MarkusAmshove
Copy link
Owner

Thats strange, so maybe it is an AS issue?

I'm so confused 😕 😄

@MarkusAmshove
Copy link
Owner

I think I've managed to resolve the issue.

Can you try and confirm with
testImplementation 'org.amshove.kluent:kluent-android:1.48'
?

@JotraN
Copy link

JotraN commented Feb 15, 2019

@MarkusAmshove,
testImplementation 'org.amshove.kluent:kluent-android:1.48' is working (without needing org.jetbrains.kotlin:kotlin-test:$kotlin_version)!!!!

Running the tests via AS and command line both work for me 🎉.

@ychescale9
Copy link
Contributor

ychescale9 commented Feb 18, 2019

@MarkusAmshove I'm curious how you fixed this with the kluent-android artifact as there's no changelog for 1.48 yet?

Also currently kluent and kluent-android versions are out of sync. Is this temporary or will they be published separately with different versions going forward?

@MarkusAmshove
Copy link
Owner

The packages are now in sync again.

This is the change you're looking for

@MarkusAmshove
Copy link
Owner

Closing this issue, as it is resolved in 1.48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants