简体   繁体   English

Android Studio:Gradle Sync 因 v4 支持库而失败

[英]Android Studio: Gradle Sync fail with v4 support library

I have been following the Android fragments tutorial which requests that I set up my project to work with the v4 library by following the Support Library Setup document here .我一直在关注 Android 片段教程,该教程要求我按照此处的支持库设置文档设置我的项目以使用 v4 库。

Here are the steps I followed.这是我遵循的步骤。

1) Make sure you have downloaded the Android Support Repository using the SDK Manager. 1) 确保您已使用 SDK Manager 下载了 Android Support Repository。

2) Open the build.gradle file for your application. 2) 打开应用程序的 build.gradle 文件。

3) Add the support library to the dependencies section. 3) 将支持库添加到依赖项部分。 For example, to add the v4 support library, add the following lines:例如,要添加 v4 支持库,请添加以下几行:

 dependencies { ... compile "com.android.support:support-v4:24.1.1" }

After following the three steps I receive these two errors:按照三个步骤后,我收到这两个错误:

Gradle project sync failed...

Error:Could not find method compile() for arguments [com.android.support:support-v4:24.1.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Please install the Android Support Repository from the Android SDK Manager.

According to the Android SDK Manager, I do have the Android Support Repository installed.根据 Android SDK Manager,我确实安装了 Android Support Repository。

I am going to continue investigating this issue as fragments appear to be a valuable tool to develop powerful Android mobile apps.我将继续调查这个问题,因为片段似乎是开发强大的 Android 移动应用程序的宝贵工具。 Help approaching this issue would be appreciated.解决此问题的帮助将不胜感激。

As Sufian requested in the comments below, here are the contents of my build.gradle file.正如苏菲安在下面的评论中所要求的,这是我的 build.gradle 文件的内容。

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        compile "com.android.support:support-v4:24.1.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

Here is a screenshot of my Android Standalone SDK Manager showing that the Android Support Repository is installed.这是我的 Android Standalone SDK Manager 的屏幕截图,显示已安装 Android Support Repository。

There are two build.gradle files in your project, one rootlevel, and one for your application.您的项目中有两个 build.gradle 文件,一个根级别,一个用于您的应用程序。 You will also see a dependencies section in the other build.gradle.您还将在另一个 build.gradle 中看到一个依赖项部分。 You need to place the compile "com.android.support:support-v4:24.1.1" in there.您需要在其中放置compile "com.android.support:support-v4:24.1.1"

您正在<PROJECT_ROOT>\\build.gradle中添加compile "com.android.support:support-v4:24.1.1"而您应该在<PROJECT_ROOT>\\app\\build.gradle添加上述依赖<PROJECT_ROOT>\\app\\build.gradle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM