Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-defaul

2022/6/2 23:24:13

本文主要是介绍Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-defaul,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

报错问题

代码中

 

 

原因:需要直接或者间接地依赖于版本 2.5.0-alpha01

在某些情况下,希望使用all-compatibility而不是all

解决办法:

在build.gradle的kotlinOptions中添加如下内容

freeCompilerArgs += [
                "-Xjvm-default=all",
        ]

 如图

 

 

 build.gradle 全部如下

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.smart"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs += [
                "-Xjvm-default=all",
        ]
    }

    buildFeatures {
        viewBinding true
        dataBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'


    //沉浸式状态栏 https://github.com/gyf-dev/ImmersionBar
    // 基础依赖包,必须要依赖
    implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
    // kotlin扩展(可选)
    implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
    // fragment快速实现(可选)已废弃
    implementation 'com.geyifeng.immersionbar:immersionbar-components:3.2.2'


    // ViewModel
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0-rc01")
    // ViewModel utilities for Compose
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0-rc01")
    // LiveData
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.5.0-rc01")
    // Lifecycles only (without ViewModel or LiveData)
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-rc01")

    // Saved state module for ViewModel
    implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.0-rc01")

    // Annotation processor
    implementation("androidx.lifecycle:lifecycle-compiler:2.5.0-rc01")
    // alternately - if using Java8, use the following instead of lifecycle-compiler
    implementation("androidx.lifecycle:lifecycle-common-java8:2.5.0-rc01")

    implementation("androidx.activity:activity-ktx:1.4.0")
    def fragment_version = "1.4.1"
    implementation("androidx.fragment:fragment-ktx:$fragment_version")
}

  

 

参考于:https://blog.csdn.net/nicolelili1/article/details/124601441



这篇关于Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-defaul的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程