0

将 Android Studio 更新到 4.2.1 并将 Build Gradle 版本更新到 4.2.1 后,我在构建项目时遇到问题。gradle-wrapper.properties 中的 gradle 版本是: distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

有什么想法可以解决这个问题吗?

错误是:

A problem occurred configuring root project Test.
> Could not resolve all artifacts for configuration :classpath.
   > Could not find gradle-4.2.1.jar (com.android.tools.build:gradle:4.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.2.1/gradle-4.2.1.jar
   > Could not find builder-4.2.1.jar (com.android.tools.build:builder:4.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.2.1/builder-4.2.1.jar
   > Could not find bundletool-1.1.0.jar (com.android.tools.build:bundletool:1.1.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/1.1.0/bundletool-1.1.0.jar
   > Could not find protos-27.2.1.jar (com.android.tools.analytics-library:protos:27.2.1).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/27.2.1/protos-27.2.1.jar

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

-----------------------------------------------------------------------------------------
// project/build.gradle
buildscript {
    ext.kotlin_version = 1.5.0
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath com.android.tools.build:gradle:4.2.1
        classpath org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
4

2 回答 2

0

从此更改您的构建脚本

repositories {
        google()
        mavenCentral()
    }

进入这个

repositories {
       google()
       jcenter()
       mavenCentral()
   }
于 2021-06-26T03:59:03.830 回答
0

我遇到了这个问题,并通过更新 gradle 解决了:

classpath 'com.android.tools.build:gradle:4.2.1'

classpath 'com.android.tools.build:gradle:4.2.2'

将其更新到最新版本。

于 2021-12-28T13:16:16.207 回答