34

After recently upgrading my android studio, I am not able to build my project anymore.

Every time I execute a build, I am struck with the following error:

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

This error persists, even though the file splash_screen.xml exists under the drawable folder.

Rebuilding, cleaning the project and invalidating caches did not work!

Adding the line android.enableAapt2=false does not resolve the real issue and I would therefore rather find the root of the problem.

The following shows my gradle.build file:

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'

Any help is kindly appreciated.

Lucas Romier
  • 901
  • 1
  • 12
  • 20
  • are you sure it is in drawable folder or in some drawable-xyz folder. Please share screenshot of directory structure – Killer Apr 22 '18 at 12:36
  • It is definitly in the main drawable folder located under src/main/res/drawable/splash_screen.xml. Changing the location in any kind did unfortunately not help – Lucas Romier Apr 22 '18 at 13:05

18 Answers18

105

In my case it was an xml selector. In the first line I had two of these (thanks to copy paste among my files):

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

and Android Studio didn't give any warning or something. Removing it fixed the problem but it needed a full clean build afterwards.

Mohsen
  • 1,620
  • 3
  • 15
  • 22
  • 6
    Note this may not be in the file that apparently gives the error! Check any XML files you recently added or modified in the project. – Matt Dec 15 '19 at 15:20
30

I fixed the error, which was probably coming from a mal-formatted copied XML file (probably some line-ending confusion)

Rewriting those fixed the error, although Android Studio displayed another file as the source of the problem, which in fact had nothing to do with the error itself.

Pratik Butani
  • 51,868
  • 51
  • 228
  • 375
Lucas Romier
  • 901
  • 1
  • 12
  • 20
3

Check your each and every XML and maybe you will find the following situation.

  • While coping code or files from other projects, maybe you forgot to add some resources like drawable, strings.

  • Check each drawable files, may Android Studio will highlight when you open that file.

Sometimes this type of error we have to find because of Android Studio stuck with errors.

Pratik Butani
  • 51,868
  • 51
  • 228
  • 375
3

In my case I deleted namespace declaration duplicate like xmlns:android="http://schemas.android.com/apk/res/android"
and I used Analyse -> inspect code tool to show the error in the log, then I resolved the error in other files xml in drawable resource.

Ayoub Anbara
  • 159
  • 2
  • 6
3

I had the same problem and I solved it when I added my icons in the drawable file to 24dp.

Copy any icon you want and paste it in the drawable file, and it will create (by default) 24dp icons.

gravity
  • 2,034
  • 2
  • 22
  • 31
3

in my case i like this : <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>

so i just remove one of them

1

In my case it was malformed splash_screen.xml which was part of "reverted commit" which actually deleted this file, but somehow it was still may be it was in active changelist.

Fixed that file and solved issue.

AskQ
  • 3,629
  • 4
  • 27
  • 54
1

In my case, it was a drawable resource file that required a higher API version as it was my minSdkVersion set in build.gradle. The main problem was that the file did not show any error until you opened it, so it was hard to find it at all. I have spent at least 4 hours trying other things, since as an error when building the project it showed other drawable resource files that did not have any problems at all. After removing the drawable that required the higher API the app built normally.

Pratik Butani
  • 51,868
  • 51
  • 228
  • 375
Marko Jankovic
  • 145
  • 1
  • 5
1

In my case, the problem is code conflict, other person changed the same file with me. The resource code is changed. When I fix the file, the problem is gone.

SherryWu
  • 11
  • 1
1

In my case: There was a file that I did not create inside a drawable file, and this file was empty and I just deleted it and the program started

mary maria
  • 11
  • 1
1

I was facing the same issue and finally solve this by

Analyze>Inspect Code

My Application was missing ending tags in one of the XML File Just Try Analyze > Inspect Code it will redirect you to the exact error.

Taslim Oseni
  • 4,610
  • 10
  • 34
  • 50
0

I faced the same problem while building a release version of my app the problem was that i had some important res files of my project inside the debug directory instead of having them inside the release dir so i fixed the problem by moving the files that were in debug inside release you can check it by viewing your project tree under project instead of android

Aleyam
  • 931
  • 1
  • 9
  • 10
0

while copy and pasting code I also pasted below line

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

Since,my xml file already contain above line and on adding this line it appear twice .

so I remove one of these line and it resolve my error

Jai Mahesh
  • 1,080
  • 8
  • 17
0

In my case , I used a wrong reference to the android resource file i.e android:color/splash_bg instead of @color/splash_bg

where splash_bg represents my custom color resource declared in res/values/colors.xml file.

0

In my case I had to remove android:src="@drawable/background" and android:src="@drawable/logo" lines from splash_screen.xml although the error was originally pointing at AndroidManifest.xml.

And like the first post is saying, make sure the <?xml version="1.0" encoding="utf-8"?> is correct in all xml files.

Husky931
  • 400
  • 3
  • 9
0

In my case I had deleted the folder "drawable"

0

I reformated code (since I didn't find error) in one of xml (vector) files that wasn't mentioned in error (I think) as mentioned also by @Lucas Romier, but file name was underlined red and it suggested then clean build and it worked then. :)

0

If you got down here and yet didn't got the answer so you might need to use mipmap. It's used to find the assets related to the target device dpi (like: mdpi, hdpi, xhdpi, ...).

So all you need to do is to address the asset from the mipmap instead of drawable.

android:resource="@mipmap/splash_screen"

Open your AndroidManifest.xml and where ever you used drawable change it to mipmap. here is some example:

enter image description here

Taba
  • 1,492
  • 2
  • 18
  • 27