AAPT错误:资源可绘制/ ...未找到

时间:2018-04-22 11:53:01

标签: android resources aapt aapt2

最近升级我的android工作室后,我无法再构建我的项目了。

每次执行构建时,都会遇到以下错误:

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)}

即使文件splash_screen.xml存在于drawable文件夹下,此错误仍然存​​在。

重建,清理项目并使缓存失效不起作用!

添加行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'

非常感谢任何帮助。

18 个答案:

答案 0 :(得分:14)

我修复了错误,这可能来自错误格式的复制xml文件(可能是一些行结束的混淆)

重写那些修复错误,虽然Android Studio显示另一个文件作为问题的根源,这实际上与错误本身无关

答案 1 :(得分:13)

在我的情况下,它是一个xml选择器。在第一行中,我有两个(感谢在我的文件之间复制粘贴):

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

,而Android Studio则未发出任何警告。删除它可以解决此问题,但之后需要进行完整的构建。

答案 2 :(得分:3)

我遇到了同样的问题,最后通过

解决了这个问题 <块引用>

分析>检查代码

我的应用程序在其中一个 XML 文件中缺少结束标记只需尝试分析 > 检查代码,它会将您重定向到确切的错误。

答案 3 :(得分:1)

就我而言,它是格式不正确的splash_screen.xml,它实际上是“还原的提交”的一部分,实际上删除了此文件,但不知何故它仍处于活动更改列表中。

修复该文件并解决了问题。

答案 4 :(得分:1)

在我的情况下,这是一个可绘制的资源文件,需要更高的API版本,因为它是我在build.gradle中设置的minSdkVersion。主要问题在于,在打开文件之前,该文件没有显示任何错误,因此很难找到它。我花了至少4个小时尝试其他事情,因为在构建项目时出现错误,它显示了其他可绘制资源文件,这些文件根本没有任何问题。在删除需要更高API的drawable之后,应用正常构建。

答案 5 :(得分:1)

我遇到了同样的问题,当我在可绘制文件中将图标添加到24dp时,我解决了该问题。

复制所需的任何图标并将其粘贴到可绘制文件中,它将默认创建24dp图标。

答案 6 :(得分:1)

在我的例子中:有一个我没有在可绘制文件中创建的文件,这个文件是空的,我刚刚删除了它,程序就启动了

答案 7 :(得分:1)

在我的情况下,问题是代码冲突,其他人与我更改了同一文件。资源代码已更改。修复文件后,问题就消失了。

答案 8 :(得分:0)

如果您到了这里但没有得到答案,那么您可能需要使用 mipmap。它用于查找与目标设备 dpi 相关的资产(例如:mdpi、hdpi、xhdpi、...)。

所以您需要做的就是从 mipmap 而不是 drawable 寻址资产。

android:resource="@mipmap/splash_screen"

打开您的 AndroidManifest.xml,并在您使用 drawable 的地方将其更改为 mipmap。这是一些示例:

enter image description here

答案 9 :(得分:0)

我在@Lucas Romier 也提到的错误(我认为)中没有提到的 xml(向量)文件之一中重新格式化了代码(因为我没有发现错误),但文件名用红色下划线表示建议然后清理构建,然后它就可以工作了。 :)

答案 10 :(得分:0)

就我而言,我喜欢这样: <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>

所以我只删除其中一个

答案 11 :(得分:0)

就我而言,尽管错误最初指向AndroidManifest.xml,但我不得不从splash_screen.xml中删除android:src="@drawable/background"android:src="@drawable/logo"行。

就像第一篇文章所说的那样,确保<?xml version="1.0" encoding="utf-8"?>在所有xml文件中都是正确的。

答案 12 :(得分:0)

在我的情况下,我对android资源文件使用了错误的引用 即用android:color/splash_bg代替@color/splash_bg

其中splash_bg代表我在res / values / colors.xml文件中声明的自定义颜色资源。

答案 13 :(得分:0)

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

<img>

因此,我的xml文件已经包含上述行,并且在添加此行时它会出现两次。

所以我删除了其中一行,它解决了我的错误

答案 14 :(得分:0)

在构建应用的发行版时,我遇到了同样的问题,问题是我的项目中有一些重要的res文件位于debug目录中,而不是放在{{1 }}目录,因此我通过将releasedebug中的文件移到release而不是project的项目树中来解决了问题。 >

答案 15 :(得分:0)

就我而言 我删除了xmlns:android =“ http://schemas.android.com/apk/res/android”之类的重复的名称空间声明 并且我使用了Analyze->检查代码工具以在日志中显示错误,并且我在可绘制资源中的其他文件xml中解决了该错误。

答案 16 :(得分:0)

检查每种XML,可能会发现以下情况。

  • 在处理其他项目的代码或文件时,可能是您忘了添加一些资源,如可绘制对象,字符串。

  • 检查每个可绘制文件,打开该文件时 Android Studio 可能会突出显示。

有时候我们必须找到这种类型的错误,因为Android Studio会因错误而卡住。

答案 17 :(得分:-1)

就我而言,我已删除文件夹“ drawable”