muetzenflo
muetzenflo

Reputation: 5682

Android Studio cannot find my resources

Android Studio cannot compile my test project, because it cannot resolve the resources. I tried some different settings for the res directory in the gradle.build, but nothing worked. Am I missing something simple here? It's a simple HelloWorld project with nothing individual in it.

I have the following project structure as it was created by the Android Studio wizard (newest release 0.2.5):

enter image description here

In my AndroidManifest.xml there is the usual app name reference: @string/app_name This string is defined in main/res/values/strings.xml (selected in the screenshot above).

The error I get from the IDE (Android Studio) is:

android-apt-compiler: [MyApplicationProject] C:\...\MyApplication\src\main\AndroidManifest.xml:6: error: 
Error: No resource found that matches the given name (at 'label' with value '@string/app_name').

The error I get from the command line when i run "gradle tasks" is:

A problem occurred configuring root project 'MyApplicationProject'.
 > Failed to notify project evaluation listener.
    > Main Manifest missing from C:\...\MyApplicationProject\src\main\AndroidManifest.xml

Upvotes: 10

Views: 32683

Answers (7)

Arnulfo B. Bataller
Arnulfo B. Bataller

Reputation: 526

I always encounter the same problem when updating, renaming or adding new resources (strings, drawables, raw files, colors, etc. Without knowing the reason why, the problem is always solved by simply renaming the app's project folder and re-opening the project.

Upvotes: 0

Viktor Brešan
Viktor Brešan

Reputation: 5528

For those who come with the same problem in year 2023, Invalidate Caches and Restart worked for me.

Upvotes: 0

Bravo
Bravo

Reputation: 105

What worked for me was to create a copy of each file that it wasn't picking up in my Drawable folder and delete the old one. For some reason it wasn't picking up any resources in my drawable file. Tried everything else I could find on Google.

Upvotes: 1

jsk
jsk

Reputation: 1

I struggled with this for a while and always had issues creating new maven project in AndroidStudio What finally worked is the following (tested with Android Studio 1.0.1)

  • Right click on POM file -> Maven -> Remove project (here if it complains, make sure to remove dependencies on the project)
  • Right click again on pom -> Maven -> Import project

Upvotes: 0

OscuroAA
OscuroAA

Reputation: 252

If you are having this problem in current Android Studio version, or something to the same extent (E.g. I added images to my drawable folder, and they were not recognized) your problem may be what I encountered.

If you ran into this problem after duplicating a project you were working on, then this new project was likely not imported correctly.

I made the mistake of copying and pasting the project in the IDE, renaming it (editing manifest), then trying to work on it. This will not work, because the new project is still accessing the original's res folder.

When duplicating a project, so as not to ruin your original you should:

  1. Go to your Android Studio project folder (Right click on your current project in the IDE, and select "Show In Explorer".
  2. Copy + Paste this project in the same directory; renaming folder accordingly to new version name.
  3. In IDE go to File > Import Project > ... And locate the directory of your new project.
  4. (Proceed to rename project in IDE accordingly. Change the package name in AndroidManifest.xml)

This way the IDE creates a new project for it, and it access the correct res folder (not that of the original).

Though this may not be the solution to many of you reading this question; I came across this question many times prior to discovering the proper way to duplicate a project.

I hope this can save someone some time.

Upvotes: 4

muetzenflo
muetzenflo

Reputation: 5682

Although it's a very old post, @ThomasW suggested to make this the official answer: It was a bug in Version 0.2.5 Ever since I use newer versions of Android Studio I didn't have this problem anymore.

Upvotes: 1

powder366
powder366

Reputation: 4421

Try add the following under defaultConfig (within android {...})

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
}

Upvotes: 6

Related Questions