首页 > 其他分享 >Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime

Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime

时间:2023-05-17 11:11:59浏览次数:50  
标签:ViewModelLazy ktx androidx implementation viewmodel runtime lifecycle

AS版本:

Android Studio Bumblebee | 2021.1.1 Patch 1
Build #AI-211.7628.21.2111.8139111, built on February 2, 2022
Runtime version: 11.0.11+9-b60-7590822 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 6
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40)

Run app时异常:

Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) and lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)

Go to the documentation to learn how to Fix dependency resolution errors.

工程是默认配置,没有做任何更改。

解决方法:

app的build.gradle中android block中增加如下配置:

    configurations {
        all {
            exclude group: 'androidx.lifecycle', module: 'lifecycle-runtime-ktx'
            exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
        }
    }    

完整build.gradle配置:

plugins {
    id 'com.android.application'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "com.aaa.bbb"
        minSdk 23
        targetSdk 33
        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
    }
    buildFeatures {
        viewBinding true
    }
    configurations {
        all {
            exclude group: 'androidx.lifecycle', module: 'lifecycle-runtime-ktx'
            exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

 

参考:

感谢万能的互联网,感谢具有奉献精神的各位同道!

https://stackoverflow.com/questions/73406969/duplicate-class-androidx-lifecycle-viewmodellazy-found-in-modules-lifecycle-view

标签:ViewModelLazy,ktx,androidx,implementation,viewmodel,runtime,lifecycle
From: https://www.cnblogs.com/xiululu/p/17407954.html

相关文章

  • Plugin execution not covered by lifecycle configuration
    异常信息:[color=red]Pluginexecutionnotcoveredbylifecycleconfiguration:com.google.code.maven-svn-revision-number-plugin:svn-revision-number-maven-plugin:1.13:revision(execution:default,phase:validate)Pluginexecutionnotcovere......
  • 解决Maven报Plugin execution not covered by lifecycle configuration
    解决Maven报Pluginexecutionnotcoveredbylifecycleconfiguration按照这个来,然后再创建maven工程和项目,可能解决问题.解禁MAVEN“Pluginexecutionnotcoveredbylifecycleconfiguration”问题[url]http://blog.sina.com.cn/s/blog_725eee7......
  • VMware Aria Suite Lifecycle 8.12 - 应用生命周期管理
    VMwareAriaSuiteLifecycle8.12-应用生命周期管理请访问原文链接:https://sysin.org/blog/vmware-aria-suite-lifecycle/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org应用生命周期管理VMwareAriaSuiteLifecycle(以前称为vRealizeSuiteLifecycleManage......
  • Plugin execution not covered by lifecycle configuration
    <build><pluginManagement><plugins><!--Thisplugin'sconfigurationisusedtostoreEclipsem2esettingsonly.IthasnoinfluenceontheMavenbuilditself.-->......
  • Angular 复习与进阶系列 – Component 组件 の Lifecycle Hooks
    前言我们在这篇和 这篇中已经学习了几个基本的LifecycleHooks.分别是constructorOnInitAfterContentInitAfterViewInitOnDestroyOnChanges这篇我们会把其余的LifecycleHooks都学完. InitGroupandChangesGroupAngular的Lifecycle可以分为两组.第一组......
  • IDEA Java项目中Maven Lifecycle功能
    功能点clean用于清除之前构建生成的所有文件,具体为清除Target目录中的所有文件,包括该目录删除了install生成的所有文件。validate用于验证项目是否正确,并且说必要的信息是否都可用。compile编译项目的源代码,主要是Java文件。test编译和运行测试代码。p......
  • Page Lifecycle API All In One
    PageLifecycleAPIAllInOne![svgimage](https://img2023.cnblogs.com/blog/740516/202303/740516-20230308231426673-1292653651.svg)https://img2023.cnblogs.co......
  • 第三方库依然使用support而非androidx怎么办
    使用AndroidStudio3.2及更高版本,您只需从菜单栏中依次选择 Refactor>MigratetoAndroidX,即可将现有项目迁移到AndroidX。重构命令使用两个标记。默认情况下,这两......
  • 0316-Java学习-092-【答疑解惑】Unknown lifecycle phase ".test.skip=true".
    一、问题描述:在IDEA的“Terminal”控制台执行如下命令报错:Unknownlifecyclephase".test.skip=true".mvncleanpackage-Dmaven.test.skip=true 错误日志详......
  • Introduction to the Build Lifecycle
     IntroductiontotheBuildLifecycleTableOfContents​​BuildLifecycleBasics​​​​SettingUpYourProjecttoUsetheBuildLifecycle​​​​Packaging​​......