为什么Android支持库在我的项目中不起作用?

时间:2014-07-07 22:14:02

标签: android compiler-errors android-support-library android-gradle

使用Android Studio,我尽可能按照https://developer.android.com/tools/support-library/setup.html的步骤操作,但它告诉我以下错误:

  

错误:无法在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@18899229上找到参数[com.android.support:appcompat-v7:18.0.+]的方法compile()。

     

请从Android SDK Manager安装Android支持存储库。   打开Android SDK Manager   compile error

但我已经安装了支持存储库和库!由于我也收到错误消息,指出compile不属于dependencies块,因此我将其更改为classpath,并得到以下类似错误:

  

错误:找不到与com.android.support:appcompat-v7:18.0.+匹配的任何版本。   要求:       :ExpenseTracker:未指定

     

请从Android SDK Manager安装Android支持存储库。   打开Android SDK Manager   could not find and proof of install

正如你在这里看到的那样,它仍然认为ASR没有安装,但截图证明,它是。那么我在这里做错了什么?

2 个答案:

答案 0 :(得分:11)

我认为你将这些行放在错误的文件中。

他们应该进入模块的 build.gradle文件,而不是项目的文件(从屏幕截图中看起来似乎是这样)。

此外,dependencies标记不应该是其他任何内容的子标记。类似的东西:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:support-v4:18.0.+"
    ...
}

编辑你看到评论了吗? :)

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

答案 1 :(得分:4)

我的问题是,在让Android Studio将Gradle插件升级到最新版本后,它已经弄乱了我模块的构建文件的依赖部分。它将依赖声明行连接在一起(除了仅仅是注释的行)。分隔行(将每个依赖声明放在一行中)修复了问题。