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

6
使用Android Studio,我尽量准确地按照https://developer.android.com/tools/support-library/setup.html上的步骤进行操作,但是出现了以下错误:

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.

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

但是我已经安装了支持库和ASR!由于我还收到了一个错误提示,即compile不属于dependencies块,所以我将其更改为classpath,并得到了以下类似的错误:

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

Please install the Android Support Repository from the Android SDK Manager. Open Android SDK Manager could not find and proof of install

正如您在这里看到的,它仍然认为ASR未安装,但是屏幕截图证明它已经安装。那么我错在哪里了?


尝试将v7:18.0.+更改为v7:20.+。 - Simas
@user3249477 我试过了。不幸的是,那并没有解决问题 :c - Ky -
2个回答

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

谢谢!我看到了评论,但是我认为这是一个平台依赖性问题。哎呀,算了 x3 - Ky -

4

我的问题是,我让Android Studio将Gradle插件升级到最新版本后,它搞乱了我的模块构建文件的依赖部分。它把依赖声明行连接在一起(除了那些只是注释的行)。把这些行分开(将每个依赖声明放在单独的一行上)可以解决这个问题。


你什么意思? - NoBugs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接