node_modules can't find com.android.tools.build:gradle:4.1.1

Viewed 769

Recently Android Studio was kind enough to offer to upgrade to gradle 6.5. Naive I was: I clicked yes, then the new upgrade occured and now everytime I build I get this error similar to:

Could not determine the dependencies of task ':app:mergeDebugAssets'.
> Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
   > A problem occurred configuring project ':react-native-fs'.
      > Could not resolve all artifacts for configuration ':react-native-fs:classpath'.
         > Could not find com.android.tools.build:gradle:4.1.1.
           Searched in the following locations:
             - https://jcenter.bintray.com/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom
           If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
           Required by:
               project :react-native-fs

my android/build.gradle file has those lines:

buildscript {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "$rootDir/../node_modules/react-native/android" }
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

So life's good for my project, but not for A LOT of modules, which have this:

buildscript {
    repositories {
        jcenter()
    }


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

To solve the issue, I need to add the google() repository. ... but I don't like manually editing any file under the node_modules/ folder as any new install with break them.

Is there a way to fix this ?

1 Answers

Just delete node_modules folder and run yarn install or npm install

reopen project in Android Studio and thats it

Related