编译时 React-native-camera 错误 android

React-native-camera error when compiling android

我尝试将我的 React Native 项目升级到最新版本 (0.59.2)。不幸的是,现在当我尝试 运行 react-native 运行-android 时,我收到了这个错误:

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.

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

android/app/build.gradle

中插入以下行
android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}

请在 android/app/build.gradle 内的 defaultConfig 块中插入以下行

missingDimensionStrategy 'react-native-camera', 'general'

missingDimensionStrategy 'react-native-camera', 'mlkit'

将 jitpack 添加到 android/build.gradle

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

Complete guide

Could not resolve project :react-native-camera. on Android

希望这对您有所帮助。

第 1 步:

将 dependencies 标签中 android/build.gradle 中的 class 路径更改为:

classpath 'com.android.tools.build:gradle:3.3.0' 

步骤:2:

将 android/gradle/wrapper/gradle-wrapper.properties 中的 gradle 版本更改为:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

第 3 步:

在 android/app/build.gradle 顶部添加:

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

第 4 步:

同时添加这两行:

maven { url "https://jitpack.io" } 
maven { url "https://maven.google.com" } 

相机现在可以使用了。

android/app/build.gradle.

defaultConfig标签中添加missingDimensionStrategy属性即可解决
android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general'
  }
}

如果您仍然遇到同样的问题,那么您必须执行以下步骤。

确保您的 gradle 构建工具版本高于 3.3.0。为此,您可以使用 3.4.1。从 android/build.gradle 文件 buildscript 依赖属性更改 gradle 构建工具版本。

buildscript {
    ...
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")
    }
}

还必须将 gradle 包装器更改为 4.4 或更高版本。您可以将 android/gradle/wrapper/gradle-wrapper.properties 中的 gradle 版本更改为此

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

最后在 android/build.gradle

的存储库标签中添加以下行
maven { url "https://jitpack.io" } 
maven { url "https://maven.google.com" }