40

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.

Konstantin Paulus
  • 1,943
  • 2
  • 10
  • 22

4 Answers4

109

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

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line
  }
}
Konstantin Paulus
  • 1,943
  • 2
  • 10
  • 22
  • Mark this as the answer, it's super helpful :) – scape Apr 18 '19 at 10:30
  • 1
    I have added this, the app builds when I run `run-android` and also when I build from Android Studio. But I get `Could not find com.google.firebase:firebase-ml-vision-face-model:12.0.1.` error when I use `./gradlew assembleRelease` – Haseeb Burki Oct 11 '19 at 07:53
  • 2
    Even after adding it , I m still getting the same Error . – Pranjal Khandelwal Apr 05 '21 at 14:21
  • I wasn't able to find ``` Insert the following lines in android/app/build.gradle > android { defaultConfig { ... missingDimensionStrategy 'react-native-camera', 'general' <-- insert this line } } Should I create this ? This is how my build.gradle looks https://codeshare.io/eVVJ9l – Piyush Mahapatra Jun 29 '21 at 10:55
  • Thank You bro.... You saved my lots of time... – Mayur Vaghasiya Aug 18 '23 at 09:48
4

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

Abolfazl Roshanzamir
  • 12,730
  • 5
  • 63
  • 79
1

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.

Piyush Mahapatra
  • 213
  • 2
  • 13
1

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" } 
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81