JavaCV& FFmpegMediaMetadataRetriever:DuplicateFileException

时间:2017-08-02 13:40:19

标签: android gradle android-gradle javacv

在我的Android项目中,我使用JavaCV,我还需要FFmpegMediaMetadataRetriever来检索给定位置的帧:

dependencies {
    ...
    compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.3.3'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'
    compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
    ...
}

在gradle编译时,它因DuplicateFileException错误而失败:

Error:Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/x86/libavcodec.so
    File1: C:\Users\pingu\.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\ffmpeg\3.2.1-1.3\65a0880fd927fe901cead47b9c4be9ae76a28764\ffmpeg-3.2.1-1.3-android-x86.jar
    File2: C:\Users\pingu\.android\build-cache\957befefe8a63ddc13213dcddf7f709338e00edc\output\jni

有没有办法在我的Android应用程序中都有这个库?提前谢谢

1 个答案:

答案 0 :(得分:0)

以下程序适用于我。

首先将这些行添加到 build.gradle 文件中:

packagingOptions {
    pickFirst 'lib/x86/libavcodec.so'
    pickFirst 'lib/x86/libavformat.so'
    pickFirst 'lib/x86/libavutil.so'
    pickFirst 'lib/x86/libswscale.so'
    pickFirst 'lib/armeabi/libavcodec.so'
    pickFirst 'lib/armeabi/libavformat.so'
    pickFirst 'lib/armeabi/libavutil.so'
    pickFirst 'lib/armeabi/libswscale.so'
    ...
}

然后编译似乎没问题,但在运行时出错:

java.lang.UnsatisfiedLinkError: [...] couldn't find "libjniopencv_core.so"

修复它:

  • 创建文件夹 app / src / main / jniLibs / {arm,armeabi,armeabi-v7a,x86}
  • opencv-3.2.0-1.3-android-x86.jar 中提取 *。所以文件到 app / src / main / jniLibs / x86 < /强>
  • opencv-3.2.0-1.3-android-arm.jar 中提取 *。所以文件到 app / src / main / jniLibs / {arm ,armeabi,armeabi-v7a}

然后重建项目