【问题标题】:Gradle Sync Failed In AS : Could not find com.android.tools.build:gradle:4.0.0AS 中的 Gradle 同步失败:找不到 com.android.tools.build:gradle:4.0.0
【发布时间】:2020-07-08 19:46:28
【问题描述】:

我是 Android 工作室的新手,我正在使用 react-native 构建我的应用程序。当我打开 android studio 时,Gradle build 开始了,我得到了这个错误

Could not find com.android.tools.build:gradle:4.0.0.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.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-share-extension
Open File

我搜索了堆栈溢出问题,我尝试了很多解决方案但对我没有任何帮助, 我已经尝试过的 gradlew cleangradlew build --refresh-dependenciesgradlew cleanBuildCache 但这些所有命令都显示相同的错误日志。 然后我删除了android/.gradleandroid/.idea 文件夹以及app.iml 文件(但仍然是同样的错误) 我也尝试过 react-native 项目目录中的npm cache clean --force 我也试过File> invalidate Caches /Restartandroid/build.gradle文件


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        googlePlayServicesAuthVersion = "16.0.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
 
        classpath('com.android.tools.build:gradle:4.0.0')
        classpath 'com.google.gms:google-services:4.3.3'
        // 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 {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        
        google()
        jcenter()
        maven { url 'https://maven.google.com/' }
        maven { url 'https://www.jitpack.io/' }
    }
}

android\gradle\wrapper\gradle-wrapper.properties

#Wed Jul 08 20:28:12 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip

android\app\build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

 
 
 
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    //adding firebase sdk
    
    //adding auth dpendecy manually
    implementation 'com.google.android.gms:play-services-auth:18.0.0'
    
    //noinspection GradleDynamicVersion
    //implementaion of react native image picker
    implementation project(':react-native-image-picker')
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.facebook.react:react-native:+"  // From node_modules
        // adding share extension
        implementation project(':react-native-share-extension')
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

 
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
 
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'

请提出我在这里遗漏的任何内容。 虽然npm run android 工作正常,我可以在模拟器上安装应用程序。 You can see my Gradle version and Gradle plugin version

gradlew tasks --stacktrace的输出

Configuration on demand is an incubating feature.


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-share-extension'.
> Could not resolve all artifacts for configuration ':react-native-share-extension:classpath'.
   > Could not find com.android.tools.build:gradle:4.0.0.
     Searched in the following locations:
       - https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.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-share-extension

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:


* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 13s

【问题讨论】:

    标签: android react-native gradle


    【解决方案1】:

    好吧,我正在回答我自己的问题。如果您在这里并且已经尝试过我上面尝试过的方法,那么您可以试一试,尝试删除node-modules 文件夹并再次运行npm install,它确实对我有用。

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 2020-09-16
      • 2020-09-22
      • 2021-08-01
      • 2019-01-05
      • 1970-01-01
      相关资源
      最近更新 更多