Android 7.0
Nougat
Default Interface Methods
Java
Android Development

Default interface methods are only supported starting with Android 7.0 Nougat

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When building Android apps with Java 8 features, you may encounter the compile error "Default interface methods are only supported starting with Android N (--min-api 24)." This happens because default interface methods (added in Java 8) require Android API level 24 (Android 7.0 Nougat) or the D8/R8 desugaring process to work on older devices. The fix depends on your target API level and build tool version — either raise minSdkVersion to 24, or enable Java 8 desugaring in your Gradle configuration so the compiler transforms default methods into compatible bytecode for older Android versions.

What Are Default Interface Methods?

Default methods let you add method implementations directly in an interface using the default keyword:

java
1public interface Logger {
2    // Abstract method — must be implemented
3    void log(String message);
4
5    // Default method — has a body, optional to override
6    default void logError(String message) {
7        log("ERROR: " + message);
8    }
9
10    default void logWarning(String message) {
11        log("WARNING: " + message);
12    }
13}
14
15public class ConsoleLogger implements Logger {
16    @Override
17    public void log(String message) {
18        System.out.println(message);
19    }
20    // logError() and logWarning() are inherited automatically
21}

This allows evolving interfaces without breaking existing implementations — a feature Java 8 introduced that Android adopted later.

Why the Error Occurs

Android compiles Java source into Dalvik/ART bytecode, not standard JVM bytecode. Prior to API 24, the Android runtime did not support invokeinterface instructions targeting default methods. When you use a default method with minSdkVersion below 24 and without desugaring enabled, the build fails:

 
Error: Default interface methods are only supported starting with
Android N (--min-api 24)

This also applies to static interface methods and lambda expressions, all of which are Java 8 features.

Desugaring transforms Java 8 bytecode into equivalent Java 7-compatible bytecode that runs on any Android version. This is the recommended approach because it does not require raising your minimum API level.

Android Gradle Plugin 4.0+

groovy
1// build.gradle (Module)
2android {
3    compileSdkVersion 34
4    defaultConfig {
5        minSdkVersion 21  // Can be lower than 24
6        targetSdkVersion 34
7    }
8
9    compileOptions {
10        // Enable core library desugaring for java.time, etc.
11        coreLibraryDesugaringEnabled true
12        sourceCompatibility JavaVersion.VERSION_1_8
13        targetCompatibility JavaVersion.VERSION_1_8
14    }
15}
16
17dependencies {
18    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
19}

Kotlin DSL (build.gradle.kts)

kotlin
1android {
2    compileSdk = 34
3    defaultConfig {
4        minSdk = 21
5        targetSdk = 34
6    }
7
8    compileOptions {
9        isCoreLibraryDesugaringEnabled = true
10        sourceCompatibility = JavaVersion.VERSION_1_8
11        targetCompatibility = JavaVersion.VERSION_1_8
12    }
13}
14
15dependencies {
16    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
17}

Older Gradle Plugin (3.x)

For AGP 3.0-3.6, desugaring is enabled by just setting source/target compatibility:

groovy
1android {
2    compileOptions {
3        sourceCompatibility JavaVersion.VERSION_1_8
4        targetCompatibility JavaVersion.VERSION_1_8
5    }
6}

AGP 3.x uses the legacy desugar tool. AGP 4.0+ uses D8/R8 for more efficient desugaring.

Fix 2: Raise minSdkVersion to 24

If your app only targets Android 7.0+, simply raise the minimum SDK:

groovy
1android {
2    defaultConfig {
3        minSdkVersion 24  // Android 7.0 Nougat
4    }
5
6    compileOptions {
7        sourceCompatibility JavaVersion.VERSION_1_8
8        targetCompatibility JavaVersion.VERSION_1_8
9    }
10}

This gives you native runtime support for default methods without desugaring, but drops support for devices running Android 6.0 and below.

Fix 3: Kotlin Projects

If your project uses Kotlin, Kotlin interfaces with default implementations compile to bytecode that works on all Android versions:

kotlin
1interface Logger {
2    fun log(message: String)
3
4    // Kotlin interface defaults work on all API levels
5    fun logError(message: String) {
6        log("ERROR: $message")
7    }
8
9    fun logWarning(message: String) {
10        log("WARNING: $message")
11    }
12}

Kotlin compiles default interface methods using a DefaultImpls companion class, which is compatible with all Android runtimes. You still need Java 8 compatibility settings if Java code in your project uses default methods.

Java 8 Features and Android API Requirements

FeatureWithout DesugaringWith Desugaring
Lambda expressionsAPI 24+Any API level
Method referencesAPI 24+Any API level
Default interface methodsAPI 24+Any API level
Static interface methodsAPI 24+Any API level
java.util.streamAPI 24+Any API level
java.timeAPI 26+Any API level
java.util.OptionalAPI 24+Any API level

Common Pitfalls

  • Setting source/target compatibility without enabling desugaring: Setting sourceCompatibility = JavaVersion.VERSION_1_8 alone does not enable desugaring on AGP 4.0+. You must also add coreLibraryDesugaringEnabled true and the desugaring dependency for core library APIs like java.time.
  • Forgetting to sync Gradle after changes: After modifying compileOptions or adding the desugaring dependency, you must sync Gradle for the changes to take effect. The error persists until the build system picks up the new configuration.
  • Confusing minSdkVersion with compileSdkVersion: compileSdkVersion determines which APIs are available at compile time, while minSdkVersion determines which devices can run the app. Setting compileSdkVersion 34 does not fix the error — you need desugaring or a higher minSdkVersion.
  • Using default methods in annotation processors or libraries: Third-party libraries that expose interfaces with default methods also trigger this error. Ensure your desugaring configuration applies to all modules, including library dependencies.
  • Not testing on older devices after enabling desugaring: Desugaring transforms bytecode at build time, but edge cases (especially with java.time or java.util.stream) can behave differently on older runtimes. Always test on a device or emulator running your minimum API level.

Summary

  • The error occurs because default interface methods require API 24+ without desugaring
  • Enable Java 8 desugaring in Gradle (coreLibraryDesugaringEnabled true + desugaring dependency) to support all API levels
  • Alternatively, raise minSdkVersion to 24 if you only target Android 7.0+
  • Kotlin interface defaults work on all API levels without special configuration
  • Always set sourceCompatibility and targetCompatibility to JavaVersion.VERSION_1_8 in your module's build.gradle

Course illustration
Course illustration

All Rights Reserved.