[英]Gradle Sync Failed In AS : Could not find com.android.tools.build:gradle:4.0.0
我是 Android 工作室的新手,我正在使用 react-native 構建我的應用程序。 當我打開 android 工作室然后 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 clean
、 gradlew build --refresh-dependencies
、 gradlew cleanBuildCache
但這些所有命令都顯示相同的錯誤日志。 然后我刪除android/.gradle
和android/.idea
文件夾還有app.iml
文件(但仍然是同樣的錯誤)我也嘗試過npm cache clean --force
從 react-native 項目目錄File> invalidate Caches /Restart
android/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
工作正常,我可以在模擬器上安裝應用程序。 可以看我的 Gradle 版本和 Gradle 插件版本
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
好吧,我正在回答我自己的問題。 如果您在這里並且已經嘗試過我上面嘗試過的方法,那么您可以試一試,嘗試刪除node-modules
文件夾並再次運行npm install
,它確實對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.