刚刚安装的Android studio,gradle报错

标签 android gradle android-gradle-plugin android-espresso

我刚刚安装了适用于 Windows 的 Android Studio,我创建了一个简单的 android 项目,其中包含一个空白 Activity 而没有修改它,但我收到了这些错误:

C:\Users\Task\AndroidStudioProjects\MyApplication\app\build.gradle

Error:(23, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.0 Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:26.+

Gradle 同步问题

Error:The SDK Build Tools revision (23.0.2) is too low for project ':app'. Minimum required is 25.0.0

我什么都没碰,我创建的每个项目都会给我这个错误,如果有人知道问题出在哪里,我将不胜感激,谢谢大家。

最佳答案

问题可能与 Android Studio 中过时的项目模板有关。您可以按照以下说明解决问题。

第一个问题:

Error:(23, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.0 Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:26.+

与 google maven 的支持库 26 相关。引用我在 https://stackoverflow.com/a/45876864/4758255 中的回答:


请注意,要使用从 revision 25.4.0 开始的支持库,我们需要添加google maven。如在 release note says :

Important: The support libraries are now available through Google's Maven repository. You do not need to download the support repository from the SDK Manager. For more information, see Support Library Setup.

阅读更多信息 Support Library Setup .

从 11.2.0 版本开始,Play 服务和 Firebase 依赖项也需要 google maven。阅读Some Updates to Apps Using Google Play servicesGoogle APIs Android August 2017 - version 11.2.0 Release note .

所以你需要像这样将 google maven 添加到你的 root build.gradle 中:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

对于 Gradle 构建工具插件版本 3.0.0,您可以使用 google() 存储库(更多信息在 Migrate to Android Plugin for Gradle 3.0.0 ):

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

第二个问题:

Error:The SDK Build Tools revision (23.0.2) is too low for project ':app'. Minimum required is 25.0.0

意味着你需要使用最低构建工具版本 25。要解决它,首先检查你的 root build.gradle。它应该包含如下内容:

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

其次,检查您的App build.gradle。它应该包含最小 buildToolsVersion 25:

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.3" // here the builToolsVersion.
  defaultConfig {
    applicationId "com.example.project"
    minSdkVersion 9
    targetSdkVersion 25

    ...
  }
  ..
}

关于刚刚安装的Android studio,gradle报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46620512/

相关文章:

java - 如何在 IntelliJ Idea 中的新 Gradle 项目中配置默认​​依赖项

找不到 Android gradle 定义方法

android - Gradle无法刷新Android Studio

android - 将 Android 应用程序的主 Activity 切换为其他名称后为 "App not installed"

android - 如何让我的 Android 应用程序在后台运行?

java - 无法在build.gradle中初始化flyway {}

android - 与调试版本相比,发布版本中的应用程序大小有所增加

android - Android SDK从23升级到26构建错误

android - Google 应用内计费,升级到 Android L Dev Preview 后出现 IllegalArgumentException : Service Intent must be explicit,

android - android 权限组的内容