找不到com.android.support:support-v4:22.0.0。 SDK更新后

时间:2015-04-02 18:17:35

标签: android android-studio android-gradle android-support-library build.gradle

在sdk更新后我无法创建一个hello world应用程序。 我的build.gradle看起来像这样

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.coders.yo"
        minSdkVersion 11
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

但是构建失败并显示

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.android.support:support-v4:22.0.0.
     Required by:
         Yo:app:unspecified > com.android.support:appcompat-v7:22.0.0

所以我添加了compile' com.android.support:support-v4:22.0.0。'现在我得到了

Error:Failed to find: com.android.support:support-v4:22.0.0.
<a href="openFile">Open File</a><br><a href="open.dependency.in.project.structure">Open in Project Structure dialog</a>

我已经更新了android sdk enter image description here 和支持库 enter image description here

过去几个小时我一直被困在里面。可以帮助我找出问题

7 个答案:

答案 0 :(得分:12)

build.gradle中的依赖项似乎是正确的。

尝试清理缓存(文件 - &gt;使缓存无效并重新启动),然后同步gradle文件并清理和构建。

在你的gradle文件中有一条奇怪的行。 最后一个gradle插件中不存在此DSL(您使用的是哪个版本?)

 runProguard false

您应该更新插件(1.1.0),gradle版本(2.2.1)并更改此行

minifyEnabled false

答案 1 :(得分:3)

  

所以我添加了compile 'com.android.support:support-v4:22.0.0.',现在我   得到

     

Error:Failed to find: com.android.support:support-v4:22.0.0.

如果您添加了相同的内容,那么我认为您的问题最后是额外的.。 :)

尝试:

compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'

答案 2 :(得分:1)

How to clear gradle cache?

这一切都在这里解释......

只需清除你的.gradle GLOBAL缓存(缓存目录)!这让我伤了2天......

答案 3 :(得分:0)

据我所知,这是因为受支持的库的版本,您需要做什么,使用当前配置不可用的版本。

  1. 只需从gradle文件中删除此行
  2. 即可
  3. 现在选择项目转到模块设置(按F12)
  4. 使用库依赖项再次添加依赖项。
  5. 使用上述步骤即可添加支持库的可用版本。

答案 4 :(得分:0)

在我的情况下,我只需要更新SDK工具和附加功能。

答案 5 :(得分:0)

如果这可能对某人有所帮助,经过多次尝试和错误后,我发现我在与“library”对应的build.gradle文件中定位了错误的SDK版本(较旧版本)。要更改此设置,您可以手动执行或转到模块设置菜单(右键单击项目文件夹 - >打开模块设置。然后在“库” - 属性中,您可以更改编译Sdk和构建工具版本。< / p>

enter image description here

显然,在将所有支持库和构建工具更新后,这对我有用。

答案 6 :(得分:0)

更改gradle版本,就像我将2.1更改为2.2.1并且它为我工作。