113

AndroidStudio3.2 Canary14 无法清理并重建并出现以下错误

Could not find com.android.tools.build:aapt2:3.2.0-alpha14-4748712.
Searched in the following locations:
    file:~/Library/Android/sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    file:~/Library/Android/sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    file:~/Library/Android/sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
Required by:
    project :app
4

17 回答 17

255

从 Android Studio 3.2 Canary 11 开始,AAPT2(Android 资产打包工具 2)的来源是 Google 的 Maven 存储库。

要使用 AAPT2,请确保您的 build.gradle 文件中有 google() 依赖项,如下所示:

buildscript {
  repositories {
      google() // here
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.2.0-alpha12'
  }
} 
allprojects {
  repositories {
      google() // and here
      jcenter()
  }
}

新版本的 AAPT2 修复了许多问题,包括改进了在 Windows 上对非 ASCII 字符的处理。

在 中添加存储库buildscript是不够的,您还需要在allprojects.

来源:https ://developer.android.com/studio/releases/#aapt2_gmaven

于 2018-05-11T11:02:49.310 回答
45

你在打开一个非常古老的项目吗?如果是这样,请确保您的应用程序的 build.gradle 具有:

apply plugin: 'com.android.application'

repositories {
    google()
    jcenter()
} 

(无论如何,这为我解决了)

于 2018-05-11T05:37:04.060 回答
20

只需添加google()您的 buidscript 和 allprojects 然后重建项目。

buildscript {
    repositories {
        google() // `enter code here`
    }
 }

allprojects {
    repositories {
        google() // `<-- here`
    }
}
于 2018-11-13T06:25:02.823 回答
7

我在伊朗,一些谷歌的存储库被限制在我的位置。当我将我的IP更改为另一个国家时,这个问题就解决了。发生此错误时,您似乎可能遇到互联网连接问题。

于 2019-12-28T07:56:23.877 回答
5

使用更新版本的等级更新您的应用的 build.grade 文件依赖项

dependencies {    
  classpath 'com.android.tools.build:gradle:3.5.3'   
}

遵循要更新到的版本的 android studio 建议。在您的成绩类路径更新并重新同步您的应用程序之后。

毕竟这重新启动你的 android studio

于 2019-12-25T14:11:22.183 回答
4

我有这个错误信息:

无法下载 aapt2-osx.jar (com.android.tools.build:aapt2:3.5.0-5435860):没有可用于离线模式的缓存版本

即使我已经为我的项目定义了所有必要的依赖项,并且在我的 build.gradle 中定义了正确的配置:

apply plugin: 'com.android.application'

repositories {
    google()
    jcenter()
} 

错误仍然发生,但这条消息让我知道发生了什么:

没有可用于离线模式的缓存版本

所以我发现我在离线工作,你需要取消选中“离线模式”然后Android Studio才能下载创建项目所需的资源

在此处输入图像描述

当您的项目再次工作时,您可以再次检查以脱机工作。

于 2020-01-23T02:07:26.737 回答
3

我通过更改android/gradle/gradle-wrapper.properties.

默认值是https\://services.gradle.org/distributions/gradle-4.10.2-all.zip,我将其更改为https\://services.gradle.org/distributions/gradle-5.4.1-all.zip并且错误消失了。

于 2019-08-17T07:51:03.290 回答
2

google()即使通过更改此行来修复我也有同样的问题

改变这个build.gradle

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

对此

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

并将其更改为gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

对此

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
于 2020-12-08T08:35:12.293 回答
2
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()  //导入旧版本项目时,一般来说该处依赖会在更改classpath中gradle版本是自动添加
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
       /*
        解决报错:Could not find com.android.tools.build:aapt2:3.3.0-5013011.
        Beginning with Android Studio 3.2 Canary 11, the source for AAPT2 (Android Asset Packaging Tool 2) is Google's Maven repository.
        To use AAPT2, make sure that you have a google() dependency in your build.gradle file, as shown here:
        */
        google() //但是此处不会,需要自主添加
        jcenter()
    }
}
于 2019-01-23T06:24:18.867 回答
0

不幸的是,以上答案都不够完整,但这对我有用。只需确保您的 build.gradel 具有以下所有内容

buildscript {
    repositories {
        google() // Check if this Google exists and is in the first
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {
        google() // Check if this Google exists and is in the first
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
于 2021-07-11T16:04:07.423 回答
0

解决方案是一个四步过程,

  1. 将 build.gradle 中的类路径更改为所需的版本。
  2. 立即同步
  3. 下载完所有文件后,您可以在 Gradle 中删除新版本并添加以前的版本。
  4. 立即同步
于 2019-09-18T05:54:19.970 回答
0

Problem happened to me when i opened my old project

Can be fixed by upgrading the tools gradle

classpath "com.android.tools.build:gradle:4.0.2"

于 2021-06-14T11:17:12.120 回答
0

就我而言,我能够通过将“Android SDK Build-Tools”更新到最新版本来解决它。

在 Android Studio 中,转到工具 -> SDK 管理器 -> 选择 SDK 工具选项卡 -> 检查是否有任何可用于 Android SDK 构建 - 工具的更新(更新到最新的 v30.0.0)。

在此处输入图像描述

于 2020-07-30T21:17:12.033 回答
0

转到 settings.gradle 并删除 projectRoot.name 文件

于 2021-04-06T05:38:13.940 回答
0

3个步骤在视频下方修复它

  1. 右侧的 Gradle 栏
  2. 切换离线模式标志
  3. 重建享受! https://www.youtube.com/watch?v=8W3a6_xwGOo&
于 2020-05-01T17:25:09.147 回答
-1

你需要在 build.gradle () 和类型 google() 中录制,这个选项在 buildscript & allproject 部分执行

于 2020-02-20T22:21:16.147 回答
-2

如果 google() 未修复,则 File -> Setting -> Build, Execution, Deployment -> Gradle

然后取消选中离线工作,完成。

于 2019-08-07T04:37:51.217 回答