Source:  Twitter logo

I tried to upgrade my react native project to the newest version (0.59.2). Unfortunately, now when trying to run react-native run-android im getting this error:

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.

I have already tried to create a new project however this results in the same error. Reinstalling the node modules didn't help either. On iOS it works fine.

Insert the following lines in android/app/build.gradle

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}
97 users liked answer #0dislike answer #097
Kape profile pic
Kape

Please insert the following line in android/app/build.gradle inside defaultConfig block either

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

or

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

Add jitpack to 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 users liked answer #1dislike answer #13
AbolfazlR profile pic
AbolfazlR

It is simple to resolve by adding missingDimensionStrategy attribute in defaultConfig tag in android/app/build.gradle.

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

If you are still having the same issue then you have to do the following steps.

Ensure that your gradle build tool version is greater than 3.3.0. You can use 3.4.1 for this purpose. Change the gradle build tool version from android/build.gradle file buildscript dependencies attributes.

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

Also have to change the gradle wrapper to 4.4 or later. You can change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this

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

Finally add the following lines in repositories tag of android/build.gradle

maven { url "https://jitpack.io" } 
maven { url "https://maven.google.com" } 
1 users liked answer #2dislike answer #21
Codemaker profile pic
Codemaker

Hope this helps.

Step 1:

Change the class path in android/build.gradle in dependencies tag to this:

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

Step:2:

Change the gradle version in android/gradle/wrapper/gradle-wrapper.properties to this:

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

Step 3:

In the android/app/build.gradle add this at the top:

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

Step 4:

Also add these two lines:

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

Camera works now.

0 users liked answer #3dislike answer #30
Piyush Mahapatra profile pic
Piyush Mahapatra

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).