Default interface methods are only supported starting with Android N

后端 未结 10 1493
天命终不由人
天命终不由人 2020-11-27 10:17

I upgraded to android studio 3.1 and I\'m getting the following error:

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


        
相关标签:
10条回答
  • 2020-11-27 10:37

    In app-level gradle, you have to write these code:

    android {
    ...
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    }
    

    They come from JavaVersion.java in Android.

    An enumeration of Java versions.

    Before 9: http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html

    After 9: http://openjdk.java.net/jeps/223

    @canerkaseler

    0 讨论(0)
  • 2020-11-27 10:38
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    
    
    android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    
    defaultConfig {
        applicationId "com.example.architecture"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
     buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
       }
    }
    dependencies {
    
    implementation 'androidx.room:room-runtime:2.2.5'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    annotationProcessor 'androidx.room:room-compiler:2.2.5'
    def lifecycle_version = "2.2.0"
    def arch_version = "2.1.0"
    
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
    implementation "androidx.cardview:cardview:1.0.0"
    }
    

    Add the configuration in your app module's build.gradle

    android {
        ...
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    0 讨论(0)
  • 2020-11-27 10:39

    My project use ButterKnife and Retro lambda, setting JavaVersion.VERSION_1_8 will not work. It always blames at ButterKnife static interface function until I found this Migrate from Retrolambda

    TL;DR

    Just add JavaVersion.VERSION_1_8 and completely REMOVE retrolambda from your project. It will build successfully.

    0 讨论(0)
  • 2020-11-27 10:49

    You can resolve this issue by downgrading Source Compatibility and Target Compatibility Java Version to 1.8 in Latest Android Studio Version 3.4.1

    1. Open Module Settings (Project Structure) Winodw by right clicking on app folder or Command + Down Arrow on Mac

    2. Go to Modules -> Properties

    3. Change Source Compatibility and Target Compatibility Version to 1.8

    4. Click on Apply or OK Thats it. It will solve your issue.

    Also you can manually add in build.gradle (Module: app)

    android {
    ...
    
    compileOptions {
            sourceCompatibility = '1.8'
            targetCompatibility = '1.8'
        }
    
    ...
    }
    
    0 讨论(0)
  • 2020-11-27 10:50

    Setting the minSdkVersion to 21 from 19 solved the issue for me.

    defaultConfig {
            applicationId "com.example"
            minSdkVersion 21
            targetSdkVersion 29
            versionCode 23
            versionName "1.0"
            vectorDrawables.useSupportLibrary = true
        }
    
    0 讨论(0)
  • 2020-11-27 10:52

    Use this code in your build.gradle

    android {
        compileOptions {
            incremental true
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    0 讨论(0)
提交回复
热议问题