当前位置: 首页 > 知识库问答 >
问题:

Gradle同步失败:无法解析配置的所有工件

冯嘉荣
2023-03-14

当试图同步Gradle时,我得到以下错误:

A problem occurred configuring project ':react-native-google-signin'.
> Could not resolve all artifacts for configuration ':react-native-google-signin:classpath'.
   > Could not find com.android.tools.build:gradle:3.6.3.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.3/gradle-3.6.3.pom
       - https://jcenter.bintray.com/com/android/tools/build/gradle/3.6.3/gradle-3.6.3.jar
     Required by:
         project :react-native-google-signin

我已经找过了,我找不到答案。这里有一个类似的问题:React原生android找不到com.android.tools.build:gradle:3.6.3

看看上面,这建议关闭脱机模式,它不是打开的,所以,不幸的是,这不是答案。

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

buildscript {
  ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0-alpha1"
      reactNativeVersion = "0.59.9"
    googlePlayServicesAuthVersion = "16.0.1"
  }
    repositories {
        google()
        maven {
          url 'https://maven.google.com/'
        }
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
        maven { url 'https://dl.bintray.com/android/android-tools' }

      maven {url "$projectDir/../node_modules/react-native/android"}
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.4.1')
        classpath 'com.google.gms:google-services:4.1.0'
        classpath 'io.fabric.tools:gradle:1.25.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        // React native video - exoplayer missing from google repos, temp fix
        maven {
            url "https://google.bintray.com/exoplayer/"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
//        configurations.all {
//            resolutionStrategy {
//                force 'com.facebook.android:facebook-android-sdk:4.28.0'
//            }
//        }
    }
}

共有1个答案

阙繁
2023-03-14

用这个替换Android/build.gradle,即在项目级别中用这个gradle

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

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

allprojects {
    repositories {
        mavenLocal()
        maven {url "https://maven.google.com"} //<---- this should be added and should be aboce jcenter
        maven {url "$rootDir/../node_modules/react-native/android"}
        jcenter()
    }
}

之后,在Android/中清除您的gradle

Gradlew Clean

然后运行react本机应用程序。

注意:在上面的代码片段中使用您自己的gradle和google服务版本

 类似资料: