【问题标题】:React-native-camera error when compiling android编译android时出现React-native-camera错误
【发布时间】:2019-03-31 15:56:37
【问题描述】:

我尝试将我的 react native 项目升级到最新版本 (0.59.2)。不幸的是,现在在尝试运行 react-native run-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 上运行良好。

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 将此标记为答案,它非常有帮助:)
    • 我添加了这个,当我运行 run-android 以及从 Android Studio 构建时,应用程序就会构建。但是当我使用./gradlew assembleRelease时出现Could not find com.google.firebase:firebase-ml-vision-face-model:12.0.1.错误
    • 即使添加了它,我仍然得到同样的错误。
    • 我找不到 ``` 在 android/app/build.gradle > android { defaultConfig { ... missingDimensionStrategy 'react-native-camera', 'general' 中插入以下行codeshare.io/eVVJ9l
    【解决方案2】:

    请在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

    【讨论】:

      【解决方案3】:

      希望这会有所帮助。

      第 1 步:

      将依赖标签中android/build.gradle中的类路径改成这样:

      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
      

      第三步:

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

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

      第四步:

      同时添加这两行:

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

      相机现在可以工作了。

      【讨论】:

        【解决方案4】:

        android/app/build.gradledefaultConfig标签中添加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的repositories标签中添加以下几行

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-07-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多