【问题标题】:Execution failed for task ':app:mergeDebugNativeLibs' while running react-native app运行 react-native 应用程序时任务 \':app:mergeDebugNativeLibs\' 执行失败
【发布时间】:2022-11-11 21:31:31
【问题描述】:

在运行反应本机应用程序时,我收到以下错误:

`

任务 :app:mergeDebugNativeLibs 失败

此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 7.0 不兼容。 使用“--warning-mode all”显示各个弃用警告。 见https://docs.gradle.org/6.9.2/userguide/command_line_interface.html#sec:command_line_warnings 574 个可操作的任务:2 个已执行,572 个最新

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':app:mergeDebugNativeLibs' 执行失败。

执行 com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 时发生故障 从输入中找到路径为“lib/armeabi-v7a/libfbjni.so”的 2 个文件: - C:\Users\nouman.gradle\caches\transforms-3\6ef14503de3c85fa1ab2aba364d580cc\transformed\jetified-react-native-0.71.0-rc.0-debug\jni - C:\Users\nouman.gradle\caches\transforms-3\64faf76bb2f0142d731347d7bfff47d4\transformed\jetified-fbjni-0.3.0\jni 如果您使用 jniLibs 和 CMake IMPORTED 目标,请参阅 https://developer.android.com/r/tools/jniLibs-vs-imported-targets

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • https://help.gradle.org 获得更多帮助

32 秒内构建失败

错误 无法安装应用程序。确保您已设置 Android 开发环境:https://reactnative.dev/docs/environment-setup。 错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务 ':app:mergeDebugNativeLibs' 执行失败。

执行 com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 时发生故障 从输入中找到路径为“lib/armeabi-v7a/libfbjni.so”的 2 个文件: - C:\Users\nouman.gradle\caches\transforms-3\6ef14503de3c85fa1ab2aba364d580cc\transformed\jetified-react-native-0.71.0-rc.0-debug\jni - C:\Users\nouman.gradle\caches\transforms-3\64faf76bb2f0142d731347d7bfff47d4\transformed\jetified-fbjni-0.3.0\jni 如果您使用 jniLibs 和 CMake IMPORTED 目标,请参阅 https://developer.android.com/r/tools/jniLibs-vs-imported-targets

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • https://help.gradle.org 获得更多帮助

32 秒内构建失败

at makeError (D:\BayQi-Customer-Mobile-App\node_modules\execa\index.js:174:9)
at D:\BayQi-Customer-Mobile-App\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (D:\BayQi-Customer-Mobile-App\node_modules\react-native\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (D:\BayQi-Customer-Mobile-App\node_modules\@react-native-community\cli\build\index.js:192:9)

info 使用 --verbose 标志运行 CLI 以获取更多详细信息。 `

我正在尝试在物理设备中运行我的 react 本机应用程序,但出现此错误。 它运行正常,但突然停止工作

【问题讨论】:

    标签: react-native gradle


    【解决方案1】:

    更新的答案

    ?>= 0.63 的补丁我们已经为所有主要版本的 react-native 准备了一个修补程序:

    ? 0.70.5:https://github.com/facebook/react-native/releases/tag/v0.70.5

    ?️ 0.69.7:https://github.com/facebook/react-native/releases/tag/v0.69.7

    ? 0.68.5:https://github.com/facebook/react-native/releases/tag/v0.68.5

    ?️ 0.67.5:https://github.com/facebook/react-native/releases/tag/v0.67.5

    ?️ 0.66.5:https://github.com/facebook/react-native/releases/tag/v0.66.5

    ?️ 0.65.3:https://github.com/facebook/react-native/releases/tag/v0.65.3

    ?️ 0.64.4:https://github.com/facebook/react-native/releases/tag/v0.64.4

    ?️ 0.63.5:https://github.com/facebook/react-native/releases/tag/v0.63.5

    通过更新到这些补丁版本,您的 Android 版本应该会重新开始工作。

    来源https://github.com/facebook/react-native/issues/35210

    旧答案

    将此添加到您的android/build.gradle

    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())
    
    allprojects {
        configurations.all {
            resolutionStrategy {
                force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
            }
        }
    

    如果这对您不起作用(使用动态版本),则将您的版本硬编码为:

    更新 React-Native 时请小心移动此版本

    allprojects {
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.react:react-native:<your version>'
            }
        }
        repositories {
        // ...
        }
    }
    

    检查此以获取更多更新https://github.com/facebook/react-native/issues/35204

    【讨论】:

    • 第一部分对我有用
    【解决方案2】:

    // Top-level build file where you can add configuration options common to all sub-projects/modules

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        // ...
    }
    
    
    allprojects {
        repositories {
    +       exclusiveContent {
    +           // We get React Native's Android binaries exclusively through npm,
    +           // from a local Maven repo inside node_modules/react-native/.
    +           // (The use of exclusiveContent prevents looking elsewhere like Maven Central
    +           // and potentially getting a wrong version.)
    +           filter {
    +               includeGroup "com.facebook.react"
    +           }
    +           forRepository {
    +               maven {
    +                   url "$rootDir/../node_modules/react-native/android"
    +               }
    +           }
    +       }
            // ...
        }
    }

    【讨论】:

    • 将此添加到您的 android/build.gradle 文件中。这是 RN0.71 更新附带的问题。
    • 我正在使用react-native-0.67.4,这个解决方法解决了我的问题,resolutionStrategy { force ... 没有
    【解决方案3】:
    【解决方案4】:

    这帮助我解决了这个问题。

    发生这种情况是因为所有模板都按范围引用了 React Native 依赖项,例如实现 com.facebook.react:react-native:+。通常这种依赖关系是从./node_modules/react-native/android 中的本地 Maven 存储库解决的,但是,由于它已发布到 Maven Central,它现在正在获取最新的 RC。

    您可以通过在您的应用程序的 Gradle 文件中使用类似此实现 com.facebook.react:react-native:0.68.2!! 的方式将 React Native 依赖项强制为您期望的版本来解决此问题。 !! 是在您的项目或其传递依赖项依赖于较新版本时限制 Gradle 升级的简写。 AFAIK Maven Central 是不可变的,并且无法删除已发布的依赖项,因此这可能是唯一的解决方案。

    File: android/app/build.gradle
    dependencies {
        implementation 'com.facebook.react:react-native:0.67.2!!'
    }
    

    参考:https://github.com/facebook/react-native/issues/35204

    【讨论】:

      【解决方案5】:

      解决方法:我进行了以下更改并且它正在工作:

      1. gradle-wrapper.properties文件,更改 gradle 版本
        distributionUrl=https://services.gradle.org/distributions/gradle-6.9-all.zip
        
        
        1. 在项目级别构建.gradle文件,添加以下行:
              dependencies {
                    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
                 }
            allprojects {
                repositories {
                  exclusiveContent {
                    // We get React Native's Android binaries exclusively through 
                       npm,
                    // from a local Maven repo inside node_modules/react-native/.
                    // (The use of exclusiveContent prevents looking elsewhere like 
                        Maven Central
                    // and potentially getting a wrong version.)
                    filter {
                      includeGroup "com.facebook.react"
                    }
                    forRepository {
                      maven {
                        url "$rootDir/../node_modules/react-native/android"
                      }
                    }
                  }
               }
        
            configurations.all {
                    resolutionStrategy {
                      force 'androidx.core:core:1.6.0'
                      force 'androidx.core:core-ktx:1.6.0'
                    }
                }
        
        1. 在应用级别构建.gradle,添加这些依赖项:
        implementation 'androidx.core:core-ktx:1.6.0',
        implementation 'androidx.core:core:1.6.0'
        

      【讨论】:

        【解决方案6】:

        在里面添加以下行安卓>build.gradle文件 -

        allprojects {
        repositories {
            ...
            exclusiveContent {
               // We get React Native's Android binaries exclusively through npm,
               // from a local Maven repo inside node_modules/react-native/.
               // (The use of exclusiveContent prevents looking elsewhere like Maven Central
               // and potentially getting a wrong version.)
               filter {
                   includeGroup "com.facebook.react"
               }
               forRepository {
                   maven {
                       url "$rootDir/../node_modules/react-native/android"
                   }
               }
           }
        }
        

        此问题发生在 2022 年 11 月 4 日。请参阅参考:https://github.com/facebook/react-native/issues/35210

        【讨论】:

          【解决方案7】:

          将此添加到您的 app/build.gradle

          android {
             // yout existing code
             packagingOptions {
                  pickFirst '**/libc++_shared.so'
                  pickFirst '**/libfbjni.so'
              }
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2022-01-12
            • 1970-01-01
            • 2019-02-27
            • 2021-07-09
            • 2020-08-11
            相关资源
            最近更新 更多