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?
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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With