gradle 从输入中找到2个路径为“lib/arm64-v8a/libc++_shared.so”的文件... -react native

zzoitvuj  于 2022-11-14  发布在  React
关注(0)|答案(4)|浏览(624)

我尝试在react-native中启用ffmpeg-kit-react-native包。示例中给出的示例命令执行成功。但我想使用libwebp将gif文件转换为webp,该文件位于名为video的包下。按照说明,我必须启用该包以使用一些库。
2.2.1在Android上启用包编辑android/build.gradle文件,并在ext.ffmpegKitPackage变量中添加包名称。

ext {
   ffmpegKitPackage = "<package name>"
}

所以我在node_module/ffmpeg-kit-react-native/android/build.gradle中添加了一行

android {
  compileSdkVersion 30

  defaultConfig {
    minSdkVersion safeExtGet('ffmpegKitPackage', 'https').contains("-lts") ? 16 : 24
    targetSdkVersion 30
    versionCode 451
    versionName "4.5.1"
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }
  lintOptions {
    disable 'GradleCompatible'
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  rootProject.ext.ffmpegKitPackage = "video" // Added this line here 

}

错误:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
   > 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
      - C:\Users\ADMIN\.gradle\caches\transforms-3\7403ebe5571a2ce5a6a5fc9876af4814\transformed\jetified-react-native-0.66.4\jni
      - C:\Users\ADMIN\.gradle\caches\transforms-3\4be54e44fe38656741a8345504588323\transformed\jetified-ffmpeg-kit-video-4.5.1-1\jni
     If you are using jniLibs and CMake IMPORTED targets, see
     https://developer.android.com/r/tools/jniLibs-vs-imported-targets

我已经试过了。/gradlew清理,但问题仍然存在。如何修复此错误?谢谢

p5fdfcr1

p5fdfcr11#

我使用的是react native 0.68.2,我的问题已通过应用以下更改得到修复。
编辑android/build.gradle并强制所有模块使用与您的项目相同的react-native版本。

allprojects {
    
    // ...

    def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

    configurations.all {
        resolutionStrategy {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}

您可以查看this以获得更多信息

qhhrdooz

qhhrdooz2#

将此添加到您的node_module/ffmpeg-kit-react-native/android/build.gradle

android{
  packagingOptions {
      pickFirst 'lib/x86/libc++_shared.so'
      pickFirst 'lib/x86_64/libc++_shared.so'
      pickFirst 'lib/armeabi-v7a/libc++_shared.so'
      pickFirst 'lib/arm64-v8a/libc++_shared.so'
  }
  rootProject.ext.ffmpegKitPackage = "video"
}

ffmpeg-kit-react-native已经在这里讨论了这个错误。https://github.com/tanersener/ffmpeg-kit/wiki/Tips#2-depending-another-android-library-containing-libc_sharedso

7fyelxc5

7fyelxc53#

您需要在您的build.gradle(app)中添加以下内容:

android {
    //2 files found for path lib/arm64-v8a/libc++_shared.so. This version of the Android Gradle Plugin chooses the f
    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }

这对我来说很有效。在react 0.68.2和0.69.x中。

c7rzv4ha

c7rzv4ha4#

android{
  packagingOptions {
      pickFirst 'lib/x86/libc++_shared.so'
      pickFirst 'lib/x86_64/libc++_shared.so'
      pickFirst 'lib/armeabi-v7a/libc++_shared.so'
      pickFirst 'lib/arm64-v8a/libc++_shared.so'
  }
  rootProject.ext.ffmpegKitPackage = "video"
}

//如果上面的代码无效,则尝试下面的代码

sourceSets.main {
    jniLibs.srcDir 'libs'
    jni.srcDirs = [] //disable automatic ndk-build call
}

相关问题