question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minimum SDK < 24 and coreLibraryDesugaring causes NoSuchMethodError in ConcurrentHashMap

See original GitHub issue

First off, I want to thank the maintainers of this repo for doing the herculean work of getting JUnit 5 up and running on Android!

I’m running into an issue where I can run my instrumentation tests just fine within Android Studio, but if I try to run them from the command line I get two sets of errors.

First off, these are the errors I’m seeing:

First error:

module.myModule.myAndroidTest > initializationError[emulator-5554 - 8.1.0] FAILED 
        java.lang.NoSuchMethodError: No static method newKeySet()Lj$/util/concurrent/ConcurrentHashMap$KeySetView; in class Lj$/util/concurrent/ConcurrentHashMap; or its super classes (declaration of 'j$.util.concurrent.ConcurrentHashMap' appears in /data/app/module.ins.test-TnAh7dSYSDIdYT5oUAsyiQ==/base.apk!classes6.dex)
        at org.junit.platform.commons.logging.LoggerFactory.<clinit>(LoggerFactory.java:36)

Second error:

module.myModule.myPackage.myOtherAndroidTest > initializationError[emulator-5554 - 8.1.0] FAILED 
        java.lang.IllegalStateException: junit-platform-runner not found on runtime classpath of instrumentation tests; please review your androidTest dependencies or raise an issue.
        at de.mannodermaus.junit5.AndroidJUnit5Builder.runnerForClass(RunnerBuilder.kt:72)

The second error is repeated for each class in my androidTest folder.

Here’s the build.gradle for the module I’m attempting to test:

apply plugin: 'com.android.library'
apply plugin: "de.mannodermaus.android-junit5"

android {
    compileSdkVersion ...

    defaultConfig {
        ...
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"
    }

    ...

    compileOptions {
        coreLibraryDesugaringEnabled=true

        sourceCompatibility = "1.8"
        targetCompatibility = "1.8"
    }

    packagingOptions {
        exclude "META-INF/LICENSE*"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
   
    ...

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'

    testImplementation "junit:junit:${rootProject.ext.junitVer}"
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.6.2"
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.6.2"

    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"

    androidTestImplementation "de.mannodermaus.junit5:android-test-core:1.2.0"
    androidTestRuntimeOnly "de.mannodermaus.junit5:android-test-runner:1.2.0"

    androidTestImplementation "org.mockito:mockito-core:3.3.3"
    testImplementation "org.mockito:mockito-core:3.3.3"
}

...

The errors I’m seeing are awfully close to the errors in this stack overflow post, but we’re not using Kotlin so the proposed solution doesn’t work for us (unless the issue is some library we’re using is using Kotlin under the hood?)

Any help anyone could be provide would be much appreciated. Thank you!

EDIT: Tried to add Kotlin to the project so I could specify the jvmTarget in the kotlinOptions block and add a dependency on the jdk8 standard library as outlined in the linked StackOverflow post but alas no luck.

EDIT: It looks like updating the minSdk to >= 24 fixes the issue.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mannodermauscommented, Aug 7, 2021

After more experimentation, I am convinced that this behavior is a bug inside the Android Gradle Plugin and/or L8 desugaring stack. I have raised an issue on the Google bug tracker for it and will lock down this ticket until there is some feedback from the Android team.

https://issuetracker.google.com/issues/195786468

1reaction
mannodermauscommented, May 5, 2022

Nothing to share, sorry. Feel free to star the ticket on the Google issue tracker (linked above) to give some visibility to it. It’s not in the realm of possibility for the plugin to address this problem, unfortunately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 8+ APIs available through desugaring
Android Studio now includes support for using a number of Java 8+ APIs without requiring a minimum API level for your app.
Read more >
Using ConcurrentHashMap::newKeySet with Android ...
This issue has been resolved by upgrading the desugaring dependency to 1.2.0 as below: dependencies { coreLibraryDesugaring ...
Read more >
ConcurrentHashMap (Java Platform SE 8 ) - Oracle Help Center
A hash table supporting full concurrency of retrievals and high expected concurrency for updates. This class obeys the same functional specification as ...
Read more >
Marcel Schnelle android-junit5 Issues - Giters
Is there a way to provide the ability for overriding compileSdkVersion ? ... Minimum SDK < 24 and coreLibraryDesugaring causes NoSuchMethodError in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found