Flutter安卓端依赖重复致CheckDuplicatesRunnable执行失败求助
问题:Flutter安卓端依赖冲突导致类重复报错
- 引入两个Flutter第三方包:
flutter_jailbreak_detection和flutter_root_jailbreak - 二者在Android平台均依赖原生库
implementation 'com.scottyab:rootbeer-lib:0.1.0',引发重复类冲突,应用无法正常运行
报错信息
Execution failed for task ':app:checkDevDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class com.scottyab.rootbeer.BuildConfig found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Duplicate class com.scottyab.rootbeer.Const found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Duplicate class com.scottyab.rootbeer.RootBeer found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Duplicate class com.scottyab.rootbeer.RootBeerNative found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Duplicate class com.scottyab.rootbeer.util.QLog found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Duplicate class com.scottyab.rootbeer.util.Utils found in modules jetified-rootbeer-0.1.0-runtime (com.github.scottyab:rootbeer:0.1.0) and jetified-rootbeer-lib-0.1.0-runtime (com.scottyab:rootbeer-lib:0.1.0) Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
已尝试但无效的方案
在App级build.gradle中添加排除依赖代码:
implementation ('com.example.library:library:1.0') { exclude group: 'com.scottyab', module: 'rootbeer' }
有效解决方法
1. 在pubspec.yaml中针对Flutter包排除依赖
直接在Flutter的依赖配置里,给其中一个冲突包排除重复的原生依赖。示例:
dependencies: flutter_jailbreak_detection: ^1.7.0 # 替换成你使用的版本号 flutter_root_jailbreak: ^1.0.5 # 替换成你使用的版本号 exclude: group: 'com.scottyab' module: 'rootbeer-lib'
2. 在Android build.gradle中配置打包规则
如果方法1无效,在android/app/build.gradle的android代码块中添加打包选项,让Gradle优先选择其中一份重复类:
android { // 其他已有配置... packagingOptions { pickFirst 'com/scottyab/rootbeer/BuildConfig.class' pickFirst 'com/scottyab/rootbeer/Const.class' pickFirst 'com/scottyab/rootbeer/RootBeer.class' pickFirst 'com/scottyab/rootbeer/RootBeerNative.class' pickFirst 'com/scottyab/rootbeer/util/QLog.class' pickFirst 'com/scottyab/rootbeer/util/Utils.class' } }
3. 二选一保留单个包
如果前两种方法仍有问题,考虑只保留flutter_jailbreak_detection或flutter_root_jailbreak其中一个,二者功能高度重叠,完全可以替代使用。
内容的提问来源于stack exchange,提问作者Vishal Zaveri
相关产品推荐
相关产品推荐

