在颤振应用程序中添加 image_picker 插件后,Gradle Build 失败
Posted
技术标签:
【中文标题】在颤振应用程序中添加 image_picker 插件后,Gradle Build 失败【英文标题】:Gradle Build failing after adding image_picker plugin in flutter app 【发布时间】:2019-07-11 11:15:58 【问题描述】:当我运行应用程序而不添加图像选择器作为依赖项时,它工作正常。但是当我添加插件并运行时,它给了我 gradle build failed 错误。
Resolving dependencies... 5.0s
Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
D8: Program type already present: android.support.v4.app.INotificationSideChannel
*********************************************************
WARNING: This version of image_picker will break your Android build if it or its dependencies aren't compatible with AndroidX.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
*********************************************************
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\142.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\118.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\94.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\124.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\88.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\136.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\157.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\103.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\163.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\151.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\127.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\100.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\166.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\139.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\97.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\115.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\160.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\169.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\106.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\154.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\148.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\112.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\172.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\133.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\109.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\91.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\121.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\130.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\145.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\27.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\52.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\18.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\43.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\19.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\51.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\60.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\36.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\34.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\42.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\28.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\50.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\33.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\37.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\2.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\9.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\25.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\45.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\32.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\38.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\39.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\44.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\57.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\26.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\8.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\31.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\30.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\56.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\13.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\14.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\21.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\49.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\7.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\12.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\15.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\55.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\58.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\6.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\20.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\46.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\11.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\59.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\24.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\29.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\54.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\16.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\41.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\5.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\10.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\3.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\17.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\23.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\47.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\40.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\53.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\35.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\4.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\48.jar, D:\fluuter_projects\motor_app_demo\build\app\intermediates\transforms\dexBuilder\debug\22.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.app.INotificationSideChannel
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
Gradle task 'assembleDebug'... Done 23.7s
Gradle task assembleDebug failed with exit code 1
【问题讨论】:
【参考方案1】:由于 Android X 支持... 避免 AndroidX 并回滚到旧版本的简单解决方案 依赖项: image_picker: 0.4.12+1
或
将 Flutter 应用迁移到 AndroidX 将您的 Flutter 应用导入 Android Studio,以便 IDE 可以按照在具有完整 IDE 支持的 Android Studio 中编辑 Android 代码中的步骤解析 Android 代码。
按照迁移到 AndroidX 的说明进行操作。
https://flutter.io/docs/development/packages-and-plugins/androidx-compatibility
https://developer.android.com/jetpack/androidx/migrate
【讨论】:
AndroidX 兼容性文档很有帮助。以上是关于在颤振应用程序中添加 image_picker 插件后,Gradle Build 失败的主要内容,如果未能解决你的问题,请参考以下文章
在颤振插件 image_picker 示例中从图库中选择图像时内存增加
运行 image_picker 时我的新 android 应用程序崩溃(基于颤振飞镖)
颤振:“失去与设备的连接。”第二次使用 image_picker 从 iOS 上的图库中选择照片
颤振 - 使用 image_picker 处理方法调用和 already_active 异常
在flutter中从image_picker包中打开相机会导致真实设备上的应用程序崩溃,但在模拟器(android)中运行良好