AAPT错误:未找到资源drawable/...

65

最近升级了我的 Android Studio,现在无法再构建我的项目了。

每次执行构建操作时,都会出现以下错误:

error: resource drawable/splash_screen (aka com.whereisthemonkey.nowalism:drawable/splash_screen) not found.
Message{kind=ERROR, text=error: resource drawable/splash_screen (aka com.whereisthemonkey.nowalism:drawable/splash_screen) not found., sources=[C:\Users\Lucas\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\cf575568f869a44c685b16e47de83a28\res\values\values.xml:1632:5-84], original message=, tool name=Optional.of(AAPT)}

尽管在drawable文件夹下存在splash_screen.xml文件,但此错误仍然存在。

重建、清理项目和无效缓存均不起作用!

添加android.enableAapt2=false这一行并不能解决真正的问题,因此我宁愿找到问题的根源。

以下是我的gradle.build文件:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'//https://github.com/bumptech/glide/issues/1939

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.whereisthemonkey.nowalism"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    // Keep the following configuration in order to target Java 8.
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            res.srcDirs += [
                    'src/main/res-backgrounds',
                    'src/main/res-jobs',
            ]
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'

    //Do not update due to dex error
    implementation 'org.apache.commons:commons-lang3:3.6'

    //Do not update due to dex error
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.google.android.gms:play-services:11.8.0'

    implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'

    implementation 'com.amitshekhar.android:android-networking:1.0.1'
    implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'

    implementation 'com.github.ome450901:SimpleRatingBar:1.4.1'

    implementation 'com.sothree.slidinguppanel:library:3.4.0'

    implementation 'com.github.esafirm.android-image-picker:imagepicker:1.12.0'
    //Do not update due to dex error
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'

    implementation 'com.github.bumptech.glide:glide:4.6.1'
    kapt 'com.github.bumptech.glide:compiler:4.6.1'//https://github.com/bumptech/glide/issues/1939

    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    implementation 'de.hdodenhof:circleimageview:2.2.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    implementation 'com.firebaseui:firebase-ui-auth:3.2.1'
    implementation 'com.android.support:support-v4:27.1.1'
}


apply plugin: 'com.google.gms.google-services'
任何帮助将不胜感激。

你确定它在drawable文件夹里还是在某个drawable-xyz文件夹里?请分享目录结构的截图。 - Shubham AgaRwal
它肯定在位于src/main/res/drawable/splash_screen.xml下的主drawable文件夹中。不幸的是,任何位置的更改都没有帮助。 - Lucas Romier
32个回答

0

当您的资产未正确捆绑时,将会出现此错误。您可以正确捆绑所有资产,或将这些资产存储在云中,并从云中获取每个资产的链接。

如果您正在尝试第二种方法,请将资产上传到个人CSP(如Google Drive / CloudFront)并获取链接。


0
在我的情况下,我已经删除了“drawable”文件夹。

0
在我的情况下,我不得不从splash_screen.xml中删除android:src="@drawable/background"android:src="@drawable/logo"这两行代码,尽管最初的错误指向的是AndroidManifest.xml。
就像第一篇帖子所说的那样,请确保所有xml文件中的<?xml version="1.0" encoding="utf-8"?>都是正确的。

0

我在一个XML(向量)文件中重新格式化了代码(因为我没有找到错误),这个文件在错误信息中没有被提及(我认为),正如@Lucas Romier所说,但是文件名被标记为红色,建议进行清理构建,然后就可以工作了。 :)


0
在我的情况下,文件 > 无效缓存构建 > 重构项目 和删除 .gradle 文件夹都没有帮助。所以我删除了一个文件夹 res\mipmap-anydpi-v26,它包含了一个冲突的文件。

0
对我来说,问题在于我拼错了drawable-mdpidrawable-hdpi等名称(我将它们写成了dawable-mdpi等)。

0

我遇到同样的问题,我注意到在调试代码时它运行得非常完美,但在发布后错误仍然存在。

如果您遇到相同的问题,请不要担心,这意味着图像已保存在调试模式下,要解决此问题,请转到文件 - 新建 - 图像素材(不要更改任何内容,只需在顶部看到“下一步”即可)res目录,将其从DEBUG更改为MAIN。您的图像资源现在可以在发布和调试模式下使用。


0
大多数情况下,当您直接将任何类型的可绘制对象复制并粘贴到Android Studio项目中时,它会被存储在Debug Drawable中,只需通过文件资源管理器从Debug Resources移动到Main Resources即可。
\app\src\debug\res\drawable\app\src\main\res\drawable

0

android:icon="@drawable/ic_bg.png"> 中移除 .png 解决了我的问题


0

在复制和粘贴代码时,我也粘贴了下面这行代码

<?xml version="1.0" encoding="utf-8"?>

由于我的 XML 文件已经包含了上述行,添加此行会导致它出现两次。

因此,我删除其中一行,解决了我的错误。


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