react-native-image-picker: Build problem: A problem occurred configuring project ':react-native-image-picker'.

Description

I tried to run react-native run-android on a project made by a developer (who I do not have contact anymore), but the build fails with the following output:

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring project ‘:react-native-image-picker’.

Could not resolve all artifacts for configuration ‘:react-native-image-picker:classpath’. Could not find any matches for com.android.tools.build:gradle:2.2.+ as no versions of com.android.tools.build:gradle are available. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml https://jcenter.bintray.com/com/android/tools/build/gradle/ Required by: project :react-native-image-picker

When i check my android studio graddle build it has the same error:

org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':react-native-image-picker:classpath'.
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run
        at java.lang.Thread.run
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find any matches for com.android.tools.build:gradle:2.2.+ as no versions of com.android.tools.build:gradle are available.
Searched in the following locations:
    https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml
    https://jcenter.bintray.com/com/android/tools/build/gradle/
Required by:
    project :react-native-image-picker

That is my build.graddle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url "https://jitpack.io" }
        jcenter()
    }
}

subprojects { 
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.0.2"
            }
        }
    }
     afterEvaluate { 
         project -> if (project.hasProperty("android")) { 
             android { 
                 compileSdkVersion 26 
                buildToolsVersion '26.0.2' 
             } 
         } 
     } 
 }

ext {
    compileSdkVersion = 26
    minSdkVersion = 16
    targetSdkVersion  = 26
    buildToolsVersion = "26.0.2"
    googlePlayServicesVersion   = "12.0.1"
    supportLibVersion = "27.1.0"
}

How to repeat issue and example

react-native run-android

Solution

How to I fix my graddle scripts to match dependencies informations?

Additional Information

  • React Native version: 0.55.4
  • Platform: Android
  • Development Operating System: Windows 10
  • Dev tools: Android SDK Tools installed versions are: 27.0.3 and 28.0.3

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 76
  • Comments: 81 (4 by maintainers)

Commits related to this issue

Most upvoted comments

If you don’t want to wait until this library will release fixed version, here is how you can fix it:

Just add it to your build.gradle under subprojects section in the root (not app/gradle)

subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

This Worked for me:

in android/build.gradle add:

subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                google()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

changing build.gradle to

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

fixed the problem for me

Changing build.gradle from: from : classpath 'com.android.tools.build:gradle:2.2.+'

to the more exact: classpath 'com.android.tools.build:gradle:2.2.3' solves the issue here

As @maikmacs and @waltershub said.

Using this on you build.gradle will solve the issue:

subprojects { subproject ->
    if (subproject.name.contains('react-native-image-picker')){
        buildscript {
            repositories {
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

Edit: as @evanjmg said, in some cases it will only work if you put it inside allprojects in your root build.gradle.

What is does: Injects a maven repository into react-native-image-picker that does contains com.android.tools.build:gradle:2.2.+.

The good:

  • Will not force us to update into the latest version of react-native-image-picker.
  • Will not force us to update our project gradle version.

The bad:

  • This is still a walkaround and should be removed once you update react-native-image-picker on your project.

I also met the question,

image

I think this is the perfect solution if you don’t want to upgrade the version,The current version number is ‘0.27.1’.

subprojects{
           if (project.name.contains('react-native-image-picker')) {
                  buildscript {
                        repositories {
                             jcenter()
                             maven { url "https://dl.bintray.com/android/android-tools/"  }
                         }
                   }
           }
}

And,you can use react-native-image-picker@0.27.2,it has been released.

experiencing same issue. Blocked with this whole day. can anyone have a fix?

The same here, started today.

@blohamen @KAuthor7112 try adding react-native-vector-icons too

if (project.name.contains('react-native-image-picker') || project.name.contains('react-native-vector-icons')) {
    buildscript {
        repositories {
            jcenter()
            maven { url "https://dl.bintray.com/android/android-tools/"  }
        }
    }
}

I just change:

classpath 'com.android.tools.build:gradle:2.3.+'

to

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

in node_modules/react-native-vector-icons/android/build.graddle And it’s work for me. It just workaround)

react-native-image-picker@0.27.2has been released, does it work?

@kelmants, @Yathousen solution works if you put it in allprojects in your root build.gradle file

I have same issue, started today

Same issue

The same mistake.

react-native-image-picker@0.27.2 has have been released npm i react-native-image-picker@0.27.2 -save

The same issue, it seems https://jcenter.bintray.com/com/android/tools folder was gone or something. What could we do?

Same here, and I can´t fix it no way I have this:

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

I cant remove the code ext… because I have another issue

Cannot get property ‘compileSdkVersion’ on extra properties extension as it does not exist

ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }

@adrispo you should change the library’s build.graddle file, not your project’s!

As @maikmacs and @waltershub said.

Using this on you build.gradle will solve the issue:

subprojects { subproject ->
    if (subproject.name.contains('react-native-image-picker')){
        buildscript {
            repositories {
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

Edit: as @evanjmg said, in some cases it will only work if you put it inside allprojects in your root build.gradle.

What is does: Injects a maven repository into react-native-image-picker that does contains com.android.tools.build:gradle:2.2.+.

The good:

  • Will not force us to update into the latest version of react-native-image-picker.
  • Will not force us to update our project gradle version.

The bad:

  • This is still a walkaround and should be removed once you update react-native-image-picker on your project.

this work for me, thanks

If you don’t want to wait until this library will release fixed version, here is how you can fix it:

Just add it to your build.gradle under subprojects section in the root (not app/gradle)

subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

Yay! this fixed the issue for me. Thank you! 👍 😄

react-native-image-picker@0.27.2has been released, does it work?

Yes. works for me.

Works for me too!!

react-native-image-picker@0.27.2has been released, does it work?

Yes. works for me.

Today has just been a bad day for native android dependencies: https://issuetracker.google.com/issues/120759347

I have also been unable to fix the issues with all suggested fixes.

changing build.gradle to

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

fixed the problem for me

Same Issue, this fixed it for me.

No,it is not working for me

If adding google() into your build.gradle doesn’t work try adding it at first place in your repositories section of node_modules/YOUR_PACKAGE/android/build.gradle file.

Thanks all for the feedback about the latest release.

It looks like the issue has been solved on local machines, but not in CI environment. That looks like a cache issue to me.

Let’s upgrade Gradle.

experiencing same issue. Blocked with this whole day. can anyone have a fix?

worked for me!

Tried the suggestion above to no avail. I’ve added the latest for react-native-image-picker. I’ve also added the subprojects closure:

 if (subproject.name.contains('react-native-image-picker')) { 
            buildscript { 
                repositories { 
                    jcenter() 
                    google() 
                    maven { url "https://dl.bintray.com/android/android-tools/" } 
                    } 
                } 
        }

and I’m receiving the following error:

> Could not resolve all artifacts for configuration ':react-native-image-picker:classpath'.
   > Could not find com.android.tools.build:gradle:2.2.3.
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar
         https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar
     Required by:
         project :react-native-image-picker

I’m actually having this exact same issue after upgrading to react-native-image-picker 0.27.2. This is only happening in my App Center builds - build works on both Mac and Windows.

It was also not working for us - both locally and on the App Center. Upgrading to 0.27.2 fixed local builds, but the App Center ones were still failing. Adding the following to build.gradle fixed the App Center builds:

subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                google()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

This is our current build.gradle file:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                google()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 21
    compileSdkVersion = 27
    targetSdkVersion = 27
    supportLibVersion = "27.1.1"
    googlePlayServicesVersion = "15.0.1"
    firebaseVersion = "17.1.0"
    firebaseCoreVersion = "16.0.1"
}

react-native-image-picker@0.27.2has been released, does it work?

Yes. works for me.

Works for me too!!

It works! Thanks!!

thank god,i resolved issue by below code:

subprojects { if (project.name.contains('react-native-image-picker')) { buildscript { repositories { jcenter() google() maven { url "https://dl.bintray.com/android/android-tools/" } } } } }

thanks guys

Can someone explain what went wrong here? Updating the library simply fixed it for me but I’d like to know what broke and how it caused this error.

  • Thanks in advance

@blohamen @KAuthor7112 try adding react-native-vector-icons too

if (project.name.contains('react-native-image-picker') || project.name.contains('react-native-vector-icons')) {
    buildscript {
        repositories {
            jcenter()
            maven { url "https://dl.bintray.com/android/android-tools/"  }
        }
    }
}
subprojects {
    if (project.name.contains('react-native-image-picker')) {
        buildscript {
            repositories {
                jcenter()
                google()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

this worked for me

@sginn Same for me after updating to 0.27.2, local build started working but my Bitrise workflow is failing. Cant seem to figure out whats wrong.

@heavyskyl thanks, but the same issue came up for react-native-vector-icons and I solved it doing the same for react-native-vector-icons’s build.graddle. The problem is my node_modules/ folder is in .gitignore and thereby it will propagate to my colleague’s projects.

Is there any contributor there to fix it in the lib’s sources? Thank you very much!