Android Studio: extension methods are not supported at this language level

The following code caused 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 did I do wrong?

+8
source share
1 answer

You are trying to use the static interface method, which is new to Java 8. It is not supported on Android prior to Android N. For more information, see Use Java 8 Language Features from the Android Guide.

Currently there is a BUG .

You must use Java 8 to compile by following the instructions. Here is a build.gradle example:

 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' } 
+9
source share

All Articles