编译Android

时间:2019-03-31 15:56:38

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

我尝试将我的react本机项目升级到最新版本(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.

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

4 个答案:

答案 0 :(得分:6)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

希望这会有所帮助。

第 1 步:

将dependencies标签中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

第 3 步:

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

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

第 4 步:

还要加上这两行:

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

相机现在可以工作了。

答案 3 :(得分:0)

通过在 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" }