【问题标题】:Could not find com.android.tools.build:aapt2:4.0.0-6051327 [duplicate]找不到 com.android.tools.build:aapt2:4.0.0-6051327 [重复]
【发布时间】:2020-10-05 16:56:50
【问题描述】:

当我在 android studio 中运行 java 文件时,会出现这个错误:

Could not find com.android.tools.build:aapt2:4.0.0-6051327.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/tools/build/aapt2/4.0.0-6051327/aapt2-4.0.0-6051327.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 :objects

提供一些信息, build.gradle 项目:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'

    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle 模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "20.0.0"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

}

gradle-wrapper.properties:

#Tue Jun 16 10:43:56 IRDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

我试过Gradle Sync Failed: could not find com.android.tools.build,但问题依然存在。安卓工作室 4.0.我是安卓新手。 任何帮助都非常感谢...

【问题讨论】:

  • tnx,但是将google()放入依赖后问题解决了{}

标签: android android-studio android-studio-4.0


【解决方案1】:

在您的 build.gradle 文件中添加 google() 依赖项。

allprojects {
  repositories {
      google() // this one is missing in your code
      jcenter()
  }
}

并使用 implementation 而不是 compile,因为它已被弃用。

【讨论】:

  • tnx,在我这样做之后,问题就解决了。即使我再次删除了 google() 但它仍然可以。正常吗?
  • 它可能被缓存了。
  • 啊哈,感谢您的回复
  • jcenter() > mavenCentral()
猜你喜欢
  • 1970-01-01
  • 2019-07-30
  • 1970-01-01
  • 1970-01-01
  • 2019-03-03
  • 1970-01-01
  • 1970-01-01
  • 2020-09-22
  • 1970-01-01
相关资源
最近更新 更多