IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> BasexxxFragment_MembersInjector is defined multiple times -> 正文阅读

[移动开发]BasexxxFragment_MembersInjector is defined multiple times

用dagger在组件化开发时,当有多个子类继承BasexxxFragment,里面都用@Inject来实例化对象的时候,编译报错:

BasexxxFragment_MembersInjector is defined multiple times。

AGPBI: {"kind":"error","text":"Type BaseBindFragment_MembersInjector is defined multiple times: /Users/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/096dfca1641ca500820ceed26817100b9ab72d8b6398592be460b1dcef6ffba9_0.jar:classes.dex, /Users/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/f7e7b7f5d31272aef30fb9cf12a2ab4c837a351a1ff24ef4e3f874fc7add7466_0.jar:classes.dex","sources":[{"file":"/User/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/096dfca1641ca500820ceed26817100b9ab72d8b6398592be460b1dcef6ffba9_0.jar"}],"tool":"D8"}
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Type base.mvvm.BaseBindFragment_MembersInjector is defined multiple times: /Users/h/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/096dfca1641ca500820ceed26817100b9ab72d8b6398592be460b1dcef6ffba9_0.jar:classes.dex, /Users/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/f7e7b7f5d31272aef30fb9cf12a2ab4c837a351a1ff24ef4e3f874fc7add7466_0.jar:classes.dex
    at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:128)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:115)
    at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:111)
    at com.android.build.gradle.internal.tasks.DexMergingWorkAction.merge(DexMergingTask.kt:805)
    at com.android.build.gradle.internal.tasks.DexMergingWorkAction.run(DexMergingTask.kt:760)
    at com.android.build.gradle.internal.profile.ProfileAwareWorkAction.execute(ProfileAwareWorkAction.kt:74)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
    at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
    at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:60)
    at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/Documents/android_project/taxidriverowner/taxidriver/build/intermediates/mixed_scope_dex_archive/out/096dfca1641ca500820ceed26817100b9ab72d8b6398592be460b1dcef6ffba9_0.jar:classes.dex
    at Version.fakeStackEntry(Version_2.2.64.java:0)
    at com.android.tools.r8.utils.a0.a(SourceFile:89)
    at com.android.tools.r8.D8.run(D8.java:11)
    at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:113)
    ... 36 more

搜索一番,问题是当基类里面没有添加过@inject注解的情况下,多个子类添加了@inject注解,就会导致生成多个BasexxxFragment_MembersInjector,,解决办法:

写一个用不着的类,在基类里面用@inject注解将其实例化一下。

需要注意的是,基类需要是抽象类,注解实例化的对象不能是private的。

demo:

import javax.inject.Inject

class Unused @Inject constructor()

基类里面通过注解实例化一个它的对象

abstract class BaseBindFragment{

// 解决dagger组件化编译报错
    @Inject
    lateinit var unused: Unused
}

相关问题:

dragger2在组件化时出现的问题BaseLazyFragment_MembersInjector - 简书

google/dagger的issues

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章           查看所有文章
加:2021-10-12 23:34:18  更:2021-10-12 23:36:56 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 23:31:17-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码