0

我一直在关注Android片段教程,该教程要求我通过遵循支持库设置文档here来设置我的项目以使用v4库。Android Studio:Gradle Sync失败,支持v4支持库

以下是我遵循的步骤。

1)确保您已经使用SDK管理器的 下载了Android支持信息库。

2)打开您的应用程序的build.gradle文件。

3)将支持库添加到依赖项部分。例如, 添加V4支持库,加上下面几行:

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

以下三个步骤后,我收到这两个错误:

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. 

根据Android SDK管理器,我确实安装了Android支持库。

我打算继续调查这个问题,因为碎片似乎是开发功能强大的Android移动应用程序的有价值工具。帮助解决这个问题,将不胜感激。

正如Sufian在下面的评论中所要求的,这里是我的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 
} 

这里是我的Android SDK独立Manager显示已安装的Android支持库的screenshot

+0

“据在Android SDK管理器,我有安装了Android的支持库。”你有没有尝试下载/安装它呢? – Sufian

+3

也发布你的build.gradle文件。 – Sufian

+0

@Sufian我更新了我的帖子以包含build.gradle文件和Android支持库安装的屏幕截图。 – dyllandry

回答

4

您的项目中有两个build.gradle文件,一个是rootlevel,另一个是您的应用程序。您还会在另一个build.gradle中看到一个依赖项部分。你需要把compile "com.android.support:support-v4:24.1.1"放在那里。

2

你加入在<PROJECT_ROOT>\build.gradlecompile "com.android.support:support-v4:24.1.1"相反,你应该添加上面依赖于<PROJECT_ROOT>\app\build.gradle