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

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

问题描述:

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

Using Android Studio, I followed the steps at https://developer.android.com/tools/support-library/setup.html as acurately as I could, but it told me the following error:


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

Error:Could not find method compile() for arguments [com.android.support:appcompat-v7:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@18899229.

请从Android SDK Manager安装Android支持存储库。
打开Android SDK管理器

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

但是我已经安装了Support Repository和Library!因为我也有一个错误,说 compile 不属于 dependencies 块,所以我把它改为 classpath ,并得到以下类似的错误:

But I have already installed the Support Repository and Library! Since I also got an error saying compile doesn't belong in the dependencies block, so I changed it to classpath, and got the following, similar error:


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

Error:Could not find any version that matches com.android.support:appcompat-v7:18.0.+. Required by: :ExpenseTracker:unspecified

请从Android SDK管理器安装Android支持存储库。
打开Android SDK管理器

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

正如你可以看到的,它仍然认为ASR没有安装,但是如截图所证明的那样。

As you can see here, it still thinks the ASR isn't installed, but as the screenshot proves, it is. So what am I doing wrong here?

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

I think you're placing these lines in the wrong file.

他们应该进入模块的 build.gradle 文件,而不是 / strong>一个(这似乎是从截图)。

They should go in the module's build.gradle file, not in the project's one (which this would seem to be, from the screenshot).

此外, dependencies 不应该是任何其他的孩子。例如:

Also, the dependencies tag should not be a child of anything else. something like:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    ...
}

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

编辑您是否看过注释? :)

EDIT Did you see the comment? :)

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