繁体   English   中英

我的 npx react-native run-android 构建失败

[英]my npx react-native run-android build fails

我的同事最近在我的项目中添加了react-native-camera 我合并了代码,当我运行npx react-native run-android时,我的构建失败了:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve project :react-native-camera.
     Required by:
         project :app
      > Cannot choose between the following variants of project :react-native-camera:
          - generalDebugRuntimeElements
          - mlkitDebugRuntimeElements
        All of them match the consumer attributes:
          - Variant 'generalDebugRuntimeElements' capability Rombot:react-native-camera:unspecified:
              - Unmatched attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'generalDebug' but wasn't required.
                  - Found react-native-camera 'general' but wasn't required.
              - Compatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.
          - Variant 'mlkitDebugRuntimeElements' capability Rombot:react-native-camera:unspecified:
              - Unmatched attributes:
                  - Found com.android.build.api.attributes.VariantAttr 'mlkitDebug' but wasn't required.
                  - Found react-native-camera 'mlkit' but wasn't required.
              - Compatible attributes:
                  - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
                  - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
                  - Required org.gradle.usage 'java-runtime' and found compatible value 'java-runtime'.

我试图删除我的节点模块,然后进行npm install ,但我仍然遇到相同的错误。 任何帮助都会很棒。 提前致谢。

删除 React-Native-Camera 依赖项并再次安装和。

cd android

./gradlew clean

并再次运行应用程序

有时react-native-cli auto-link功能会失败。

尝试手动链接库。 按着这些次序....

  1. npm install --save react-native-camera@git+https://git@github.com/react-native-community/react-native-camera.git
  2. react-native link react-native-camera
  3. npx react-native run-android

同样的问题在这里得到了照顾:

“此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 7.0 不兼容。” -反应本机

android/app/build.gradle添加这一行

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}

在此之后,如果您收到此错误: “任务 ':app:mergeDexDebug' react-native 的执行失败”

参考这个链接:

https://www.codegrepper.com/code-examples/javascript/Execution+failed+for+task+%27%3Aapp%3AmergeDexDebug%27+react-native

使用以下命令

npm cache clean --force

然后通过运行转到android文件夹

cd android 

然后运行

 ./gradlew clean

然后运行

npx react-native link react-native-camera

最后运行你的项目

npx react-native run-android

在./android/app/build.gradle 中插入这一行:

defaultConfig {... missingDimensionStrategy 'react-native-camera', 'general' }

在 ./android/app/build.gradle 中插入这一行

defaultConfig { ... targetSdkVersion rootProject.ext.targetSdkVersion missingDimensionStrategy 'react-native-camera', 'general' versionCode 1 versionName "1.0" }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM