Android Studio中支持库support:appcompat-v7:22.0.0出现资源找不到的错误。

5

我尝试按照这个指南https://github.com/codepath/android_guides/wiki/Design-Support-Library添加设计支持库,但遇到了问题。

dependencies {
          compile 'com.android.support:appcompat-v7:22.2.0'
} 

尝试添加此内容,但在构建时出现了许多XML错误。
Error:(24, 63) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_default_mtrl_alpha').
Error:(25, 93) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_default_mtrl_alpha').
Error:(26, 33) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_textfield_activated_mtrl_alpha').

Error:(20, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_dark').
Error:(21, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_dark').
Error:(20, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_light').
Error:(21, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_light').

Error:(18, 29) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_pressed_holo_light').
Error:(22, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_dark').
Error:(23, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_dark').

Error:(22, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_light').
Error:(23, 118) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_list_selector_disabled_holo_light').
Error:(19, 27) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_btn_rating_star_off_mtrl_alpha').
Error:(21, 27) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_btn_rating_star_off_mtrl_alpha').

Error:(23, 27) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_btn_rating_star_on_mtrl_alpha').
Error:(19, 29) No resource found that matches the given name (at 'drawable' with value '@drawable/abc_btn_switch_to_on_mtrl_00001').

Information:BUILD FAILED

这是以下的 build.gradle 文件:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.hp.navigationexercise"
        minSdkVersion 21
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:support-annotations:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
}

你的drawable文件中有这些值吗?你尝试过Build --> clean了吗? - Kevin Cronly
1
只需将您的目录路径缩短到项目即可。 - Yashwanth
@Yashwanth 如果目录路径在中间文件夹中,如何缩短它? - Janardhan R
4个回答

11

当文件名太长时,我遇到了这个错误。

如果您在Windows下运行,则build/intermediates/...文件会变得非常长。 如果发生这种情况,您将会遇到这样奇怪的错误。


我不会想到这可能是个问题。对我有用,谢谢。 - Edison Spencer
@JanardhanR 我记不太清了,但我想我把项目位置移到更靠近我正在工作的目录(Windows)的地方了。 - Edison Spencer
@EdisonSpencer 我也是这样做的,但还是出现了新的错误。不管怎样,感谢您的回复。 - Janardhan R

2
我通过在gradle文件的defaultConfig中添加multiDexEnabled true来解决此问题。并且通过添加以下内容:
 dexOptions {
        javaMaxHeapSize "4g"
    }

defaultConfig之后。

1

由于我遇到了同样的问题,而且没有完整的答案,所以我会发布它。

正如@Brian Donovan-Smith所提到的那样,当一个或多个文件名太长(超过260个字符)时,就会出现问题。值得注意的是,名称包括整个路径。所以,在我的情况下,这就是问题所在,我通过将源文件夹移动到靠近C:的位置来解决它。


0

请确保您已通过SDK管理器下载了计算机上的文件,就像本指南中所示:https://developer.android.com/tools/support-library/setup.html(向下滚动至“使用资源添加库”)

仅靠Gradle无法完成此操作,您需要通过SDK管理器进行下载,因为此库包括资源:

某些支持库包含超出编译代码类的资源,例如图像或XML文件。例如,v7 appcompat和v7 gridlayout库包含资源。


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