Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option
报错问题
代码中
原因:需要直接或者间接地依赖于版本 2.5.0-alpha01
在某些情况下,希望使用all-compatibility
而不是all
解决办法:
在build.gradle的kotlinOptions中添加如下内容
1 2 3 | freeCompilerArgs += [ "-Xjvm-default=all" , ] |
如图
build.gradle 全部如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 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
分类:
问题
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人