Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Android app crashes on older devices with a missing java.nio.file class

Errorjava.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/LinkOption;

Short answer

The app uses a Java API from java.nio.file that the older Android version on the device does not have. Since Android Gradle Plugin 7.4.0, desugaring can supply a subset of those classes. Enable core library desugaring, add the desugar_jdk_libs dependency, and check that your plugin version is 7.4 or newer.

  • Applies to Android Gradle Plugin 8.x, desugar_jdk_libs 2.0.3, Gradle 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the minSdk and desugaring settings in the app module. The crash happens only on devices older than the API level that introduced the class, so also note the Android version of the device that crashes.

    grep -n "minSdk\|isCoreLibraryDesugaringEnabled\|coreLibraryDesugaring\|com.android.application" app/build.gradle*
  2. 2Match what you see, then jump to its fix

    1. 1The crash is on an older Android version, and the build file has no coreLibraryDesugaring dependencyCore library desugaring is not enabledFix
    2. 2Desugaring is enabled, but the plugin version in the project is below 7.4.0, or the desugar_jdk_libs version is 1.xThe Android Gradle Plugin is older than 7.4.0Fix

What does the error look like?

  • java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/LinkOption;
  • NoClassDefFoundError: Failed resolution of: [Ljava/nio/file/LinkOption;

Cause 1 of 2

Core library desugaring is not enabled

1Check

Android documents that, with plugin 7.4.0 or higher, a subset of java.nio.file becomes available through desugaring, but only after you turn the feature on in the app module.

grep -n "coreLibraryDesugaring" app/build.gradle*

2Fix

Enable the flag in compileOptions, add multiDexEnabled when minSdk is 20 or lower, and add the library dependency.

android {
    defaultConfig {
        multiDexEnabled = true   // needed when minSdk is 20 or lower
    }
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}

3Verify

Rebuild and run on the older device or emulator that crashed.

./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

The Android Gradle Plugin is older than 7.4.0

1Check

The java.nio.file subset arrives with plugin 7.4.0 and desugar_jdk_libs 2.0.x. The documented pairing is 2.0.3 with plugin 7.4 or higher; 1.2.3 is for 7.3 and 1.1.9 is for 4.0 to 7.2.

grep -rn "com.android.application\|desugar_jdk_libs" --include=*.gradle --include=*.kts --include=*.toml .

2Fix

Upgrade the plugin to 7.4 or newer, then use desugar_jdk_libs 2.0.3 as in cause 1.

// gradle/libs.versions.toml (or the plugins block)
agp = "8.7.3"

3Verify

Sync the project and rebuild. The version pair is accepted by the build.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Turn on core library desugaring when you raise the Java language level or add a library that uses newer Java APIs.
  • Run the app on an emulator at your minSdk before each release.
  • Keep the Android Gradle Plugin current, as the documentation ties desugar_jdk_libs versions to plugin versions.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.