Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Extension Methods are not supported at this language level

The following code produced the error "Extension Methods are not supported at this language level" in android studio:

public interface Test {
 static String Test2(String A) {
    return "";
    }
}

AS 2.0 Beta 2

What have I done wrong?

like image 899
Jeff Avatar asked Feb 07 '16 22:02

Jeff


1 Answers

You're trying to use a static interface method, which is a feature new in Java 8. It is not supported in Android until Android N. For more information see Use Java 8 Language Features form the Android Guides.

Still there's a BUG for the moment.

You have to use Java 8 to compile by following the mentioned instructions. Here's an example of build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-N'
    buildToolsVersion "24.0.0-rc3"

    defaultConfig {
        applicationId "example.com.examplejdk8"
        minSdkVersion 24
        targetSdkVersion 'N'
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0-alpha2'
    compile 'com.android.support:design:24.0.0-alpha2'
}
like image 195
Souhaib Guitouni Avatar answered Nov 20 '22 12:11

Souhaib Guitouni