编译Android时的React-Native-Camera错误

Kap*_*ape 8 reactjs react-native react-native-camera

我试图将我的React Native项目升级到最新版本(0.59.2)。不幸的是,现在尝试运行react-native run-android im时出现此错误:

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':
          - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
          - Found com.android.build.api.attributes.VariantAttr 'generalDebug' but wasn't required.
          - 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'.
          - Found react-native-camera 'general' but wasn't required.
      - Variant 'mlkitDebugRuntimeElements':
          - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
          - Found com.android.build.api.attributes.VariantAttr 'mlkitDebug' but wasn't required.
          - 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'.
          - Found react-native-camera 'mlkit' but wasn't required.
Run Code Online (Sandbox Code Playgroud)

我已经尝试创建一个新项目,但是这会导致相同的错误。重新安装节点模块也无济于事。在iOS上运行正常。

Kap*_*ape 24

将以下行插入 android/app/build.gradle

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 即使添加后,我仍然遇到相同的错误。 (2认同)

Abo*_*zlR 6

请将以下行插入到android/app/build.gradle内部defaultConfig块中

missingDimensionStrategy 'react-native-camera', 'general'
Run Code Online (Sandbox Code Playgroud)

或者

missingDimensionStrategy 'react-native-camera', 'mlkit'
Run Code Online (Sandbox Code Playgroud)

添加jitpack到android/build.gradle

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}
Run Code Online (Sandbox Code Playgroud)

完整指南

无法解析项目:react-native-camera。在安卓上