Lucas Romier
Lucas Romier

Reputation: 1367

AAPT error: resource drawable/... not found

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.

Upvotes: 69

Views: 127784

Answers (30)

MrNams
MrNams

Reputation: 645

In my case it got fixed after adding "ic_push_small.xml" in drawable folder

\Platforms\Android\Resources\drawable\ic_push_small.xml

Upvotes: 0

djdance
djdance

Reputation: 3209

In my case (I tried a lot) all I had to do is remove C:\Users\djdance\AppData\Local\Android\sdk\platforms\android-28 and switch compileSdk to 29. Suddenly in Jan 2024 sdk 28 wont work anymore for me. It existed, lint can find resources, but AAPT can not build resources from 28 now.

Upvotes: 0

Sk1droW
Sk1droW

Reputation: 41

In my case, I has multimodule project, which sets attributes in styles/themes from one of the imported libraries. The problem is that, module in which we set this attributes doesn't import this library (in which attributes are located)

Issue can be fixed:

  1. By importing this library (through implementation(...) in dependency {...} block in your module gradle file) into the module where reseted attributes are placed
  2. By moving the code where we set these attributes to module that already import library, where they are declared

Upvotes: 1

Gos Cb
Gos Cb

Reputation: 73

removing .png from android:icon="@drawable/ic_bg.png"> solved my issue

Upvotes: 1

Shrivatsa Kulkarni
Shrivatsa Kulkarni

Reputation: 1

This error is caused when your assets are not bundled properly. Either you can bundle all your assets correctly or store those assets in cloud and get the link of each asset from cloud.

If you are trying second method, try uploading assets into a personal CSP like google drive/cloudfront and get the links.

Upvotes: 0

riswan
riswan

Reputation: 91

in my case under drawable folder i changed the image which is declared same in androidmanifest file

Upvotes: 1

Faysal SANDA
Faysal SANDA

Reputation: 77

1 - Go to app folder and delete build folder
2 - Click on File -> Invalide Caches - Invalide and Restart

Upvotes: 1

ProgrammerJibon
ProgrammerJibon

Reputation: 71

Most of the time, when you copy and past any kind of drawable to your project directly to Android Studio, it stored in Debug Drawable, just move by File Explorer from Debug Resources to Main Resources.

From \app\src\debug\res\drawable

To \app\src\main\res\drawable

Upvotes: 0

monjan
monjan

Reputation: 1

I was facing the same issue , I noticed while debugging the code it worked perfectly but during reliease then the bug would persist .

I f you are facing the same issue don't worry , It means the image has been saved on debug mode and to fix the issue go to FILE - NEW - IMAGE ASSET (don't change anything just click next on top where you see) res directory change it from DEBUG to MAIN . your image asset can now be used on both release and debug mode.

Upvotes: 0

R3S
R3S

Reputation: 11

In my case, I had made drawable files that were all debug classification and had to go back and make a release classification equivalent. After doing this it worked on the first try.

Upvotes: 1

fjoseph1313
fjoseph1313

Reputation: 11

If you have put together your own icon ready for store release, be sure not to include the extension of the icon in your xml file. it will always fail. in my case it was this..

 <bitmap android:gravity="center" android:src="@drawable/myAppSplashLogo.png"/>

and the right way to do it is to remove the .png extension.

 <bitmap android:gravity="center" android:src="@drawable/myAppSplashLogo"/>

Upvotes: 1

Youzef
Youzef

Reputation: 838

I had the same issue. Solved it by manually adding

dependencies {
    ...
    implementation project(':react-native-splash-screen')
}

even after linking with react-native. Also added

protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);  // Added this
    super.onCreate(savedInstanceState);
}

Upvotes: 0

CoolMind
CoolMind

Reputation: 28793

In my case File > Invalidate Caches, Build > Rebuild Project, removing .gradle folder didn't help. So I removed a folder res\mipmap-anydpi-v26 that contained a conflicting file.

Upvotes: 0

Adnan
Adnan

Reputation: 1281

for me the problem was that i misspelled the names of drawable-mdpi, drawable-hdpi, etc. (I wrote them as dawable-mdpi, etc.)

Upvotes: 0

Raihan Mahamud
Raihan Mahamud

Reputation: 63

copy drawable folder all file and paste drawable_v24 folder your own project. re run. I hope this is work.

Upvotes: -1

Eray Hamurlu
Eray Hamurlu

Reputation: 783

copy "res" folder from another project (where is res folder - android/app/src/main) paste your own project. re run.

Upvotes: -1

MakiX
MakiX

Reputation: 446

In my case it was a duplicated:

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

in a drawable ressource file

Upvotes: 3

Taba
Taba

Reputation: 4316

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

Upvotes: 3

Mihajlo Nestorović
Mihajlo Nestorović

Reputation: 1

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. :)

Upvotes: 0

Zahid Iqbal
Zahid Iqbal

Reputation: 484

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.

Upvotes: 8

Ayoub Anbara
Ayoub Anbara

Reputation: 473

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.

Upvotes: 11

mary maria
mary maria

Reputation: 11

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

Upvotes: 1

CodingSkuy&#39;s
CodingSkuy&#39;s

Reputation: 89

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

Upvotes: 4

Alan Soares
Alan Soares

Reputation: 19

In my case I had deleted the folder "drawable"

Upvotes: 0

SherryWu
SherryWu

Reputation: 11

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.

Upvotes: 1

Husky931
Husky931

Reputation: 745

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.

Upvotes: 0

Mohsen
Mohsen

Reputation: 2199

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.

Upvotes: 142

Isaac Pitwa
Isaac Pitwa

Reputation: 410

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.

Upvotes: 0

Welcome_back
Welcome_back

Reputation: 1445

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

Upvotes: 0

Marko Jankovic
Marko Jankovic

Reputation: 155

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.

Upvotes: 2

Related Questions