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

时间:2020-01-10 10:24:18

标签: android reactjs react-native dependencies react-native-camera

我的同事最近将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,但仍然遇到相同的错误。任何帮助都会很棒。预先感谢。

4 个答案:

答案 0 :(得分:0)

有时auto-link的{​​{1}}功能失败。

尝试手动链接库。请按照下列步骤。...

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

答案 1 :(得分:0)

删除React-Native-Camera依赖项,然后重新安装。运行

cd android

./gradlew clean

然后再次运行应用

答案 2 :(得分:0)

这里也有同样的问题:

"Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0." -REACT-NATIVE

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

答案 3 :(得分:0)

使用以下命令

child: FutureBuilder<File>(
  key: ValueKey(imageUrl), // or use UniqueKey()  
  ...

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

npm cache clean --force

然后运行

cd android 

然后运行

 ./gradlew clean

最后运行你的项目

npx react-native link react-native-camera