Gradle Sync在AS中失败:找不到com.android.tools.build:gradle:4.0.0

时间:2020-07-08 19:46:28

标签: android react-native gradle

我是Android Studio的新手,并且正在使用react-native构建我的应用程序。当我打开android studio时,Gradle构建开始,并且出现此错误

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文件(但仍然是相同的错误) 我也尝试过从本机项目目录中的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

1 个答案:

答案 0 :(得分:0)

嗯,我在回答我自己的问题。如果您在这里,并且已经尝试了上面的尝试,则可以尝试一下,尝试删除node-modules文件夹,然后再次运行npm install,从字面上看它对我有用。