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

标签 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文件(但仍然是相同的错误)
我也尝试过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 versiongradlew 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

最佳答案

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

关于android - Gradle Sync在AS中失败:找不到com.android.tools.build:gradle:4.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62802548/

相关文章:

java - 如何获取 Activity 时间表的颜色?

android - AudioTrack、SoundPool 或 MediaPlayer,我应该使用哪个?

android - 如何在Gradle中使用Transform API?

android - 如何在 LinearLayout 中拉伸(stretch)子元素

android - 尝试在空对象引用上调用虚拟方法 'boolean abi44_0_0...FabricViewStateManager.hasStateWrapper()'

react-native - 在 react-native-router-flux 中禁用特定场景的 header

android - 无法使用 react-native 应用在 android 模拟器上登录 Google 帐户

android - 将 C++ 添加到 Android Studio 2.2

eclipse - Gradle-如何在Eclipse外下载飞船

android - 在 ActionBarSherlock 中使用自定义布局构建 ActionMode