rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
141 stars 18 forks source link

Conflicts with the ffmpeg-kit package #302

Open 842787863 opened 2 days ago

842787863 commented 2 days ago

The following error occurs when ffmpeg_kit_flutter_full and opencv_dart exist: Execution failed for task ':app:mergeDebugNativeLibs'.

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction 2 files found with path 'lib/arm64-v8a/libavcodec.so' from inputs:

  • D:\ShopProject\video_clip_craft\build\opencv_dart\intermediates\library_jni\debug\jni\arm64-v8a\libavcodec.so
  • C:\Users\Administrator.gradle\caches\transforms-3\40a96147af533123315227078a4d7b92\transformed\jetified-ffmpeg-kit-full-6.0-2.LTS\jni\arm64-v8a\libavcodec.so While you can use pickFirst to resolve conflicts roughly, other functionality, such as path_provider, may be broken
abdelaziz-mahdy commented 2 days ago

Note: this will pick the first one it finds, if you need a specific one we will need to configure this package to check first if there is ffmpeg files and if there is dont include ours,

  1. Open your app-level build.gradle file (android/app/build.gradle).
  2. Add the following under the android block in the packagingOptions section:
android {
    ...
    packagingOptions {
        pickFirst 'lib/arm64-v8a/libavcodec.so'
        pickFirst 'lib/armeabi-v7a/libavcodec.so'
        pickFirst 'lib/x86/libavcodec.so'
        pickFirst 'lib/x86_64/libavcodec.so'
    }
}
  1. Sync the Gradle project and rebuild.

This configuration ensures that the build process picks one version of libavcodec.so to avoid the conflict without affecting other libraries.

rainyl commented 2 days ago

Thanks for the solution from @abdelaziz-mahdy

If you do not use videoio module to read and save videos, replace opencv_dart with opencv_core.

But it you need it, I have no better solutions than @abdelaziz-mahdy provided, we cant control the version of ffmpeg used by ffmpeg-kit.

Maybe the most compatible solution is keeping the same version as ffmpeg-kit when compiling opencv, and make opencv_dart depend on ffmpeg-kit, but ffmpeg-kit doesn't support windows and linux...

842787863 commented 2 days ago

Thanks for the solution from @abdelaziz-mahdy

If you do not use videoio module to read and save videos, replace opencv_dart with opencv_core.

But it you need it, I have no better solutions than @abdelaziz-mahdy provided, we cant control the version of ffmpeg used by ffmpeg-kit.

Maybe the most compatible solution is keeping the same version as ffmpeg-kit when compiling opencv, and make opencv_dart depend on ffmpeg-kit, but ffmpeg-kit doesn't support windows and linux...

Thank you very much, the issue has been resolved. By the way, it's an amazing library!

842787863 commented 2 days ago

Note: this will pick the first one it finds, if you need a specific one we will need to configure this package to check first if there is ffmpeg files and if there is dont include ours,

  1. Open your app-level file ().build.gradle``android/app/build.gradle
  2. Add the following under the block in the section:android``packagingOptions
android {
    ...
    packagingOptions {
        pickFirst 'lib/arm64-v8a/libavcodec.so'
        pickFirst 'lib/armeabi-v7a/libavcodec.so'
        pickFirst 'lib/x86/libavcodec.so'
        pickFirst 'lib/x86_64/libavcodec.so'
    }
}
  1. Sync the Gradle project and rebuild.

This configuration ensures that the build process picks one version of to avoid the conflict without affecting other libraries.libavcodec.so

Thank you, using pickFirst can temporarily resolve the issue, but it may cause other dependency problems.

rainyl commented 2 days ago

@842787863 Thanks~ may i ask that how did you solve it, use opencv_core or some thing else? which can help others with same issue.

842787863 commented 1 day ago

@rainyl Thank you again. I choose to use opencv_core, although it lacks IO capabilities, I can compensate with the Android and iOS system APIs.

rainyl commented 1 day ago

aha, you are welcome. I will leave the issue open to remind myself, have fun with opencv~