The layout <layout> in layout has no declaration in the base layout folder [error]

AndroidXmlAndroid Studio

Android Problem Overview


After migrating to Android Studio 3.2, API 28, I am getting the following error on my app's layout:

> The layout in layout has no declaration in the base layout > folder; this can lead to crashes when the resource is queried in a > configuration that does not match this qualifier

One of the layouts that I am getting this error is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:orientation="vertical"
	android:background="@null" >

      <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top|center_horizontal"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello_world"
            android:src="@drawable/loading_top" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello_world"
            android:src="@drawable/loading_bottom" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:contentDescription="@string/hello_world"
            android:background="@color/white"
            android:layout_marginBottom="5dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:src="@drawable/loading_logo" />

        <ImageView
            android:id="@+id/loading"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center|center_vertical"
            android:layout_marginBottom="0dp"
            android:layout_marginTop="0dp"
            android:contentDescription="@string/hello_world"
            android:scaleType="fitXY"
            android:src="@null" />
    </FrameLayout>
</LinearLayout>

I get the error on the first line of the first LinearLayout.

Does anyone know how to solve this error?

Thank you

UPDATE: Answered my question with what has resolved the problem for me

Android Solutions


Solution 1 - Android

In my case closing and reopening Android studio solved the problem. Rebuilding the project or clearing the cache didn't help.

Solution 2 - Android

You can also try this :

File => Invalidate Caches / Restart => Invalidate and Restart.

screenshot

Solution 3 - Android

In my case it was the use of capital letters in the file name. I left everything in lowercase and it was fixed.

Solution 4 - Android

If you devise your layout : layout-sw320dp layout-sw480dp layout-sw600dp layout-sw720dp ....

you should add layout by default like this:

enter image description here

Solution 5 - Android

I just did Build > Clean Project

Solution 6 - Android

I received this error when moving layout files between Gradle modules. I didn't have to go so far as to invalidate caches as it resolved itself when I restarted Android Studio and cleaned the project. It seems likely to be an IDE bug.

Solution 7 - Android

Invalidate Cache / Restart solved my problem.

Solution 8 - Android

In my case i resolved that with this:

the Android say me this id-error:MissingDefaultResource as documentation say:

> If a resource is only defined in folders with qualifiers like -land or > -en, and there is no default declaration in the base folder (layout or values etc), then the app will crash if that resource is accessed on a > device where the device is in a configuration missing the given > qualifier. > > As a special case, drawables do not have to be specified in the base > folder; if there is a match in a density folder (such as > drawable-mdpi) that image will be used and scaled. Note however that > if you only specify a drawable in a folder like drawable-en-hdpi, the > app will crash in non-English locales. > > There may be scenarios where you have a resource, such as a -fr > drawable, which is only referenced from some other resource with the > same qualifiers (such as a -fr style), which itself has safe > fallbacks. However, this still makes it possible for somebody to > accidentally reference the drawable and crash, so it is safer to > create a default dummy fallback in the base folder. Alternatively, you > can suppress the issue by adding tools:ignore="MissingDefaultResource" > on the element. > > (This scenario frequently happens with string translations, where you > might delete code and the corresponding resources, but forget to > delete a translation. There is a dedicated issue id for that scenario, > with the id ExtraTranslation.)

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      tools:ignore="MissingDefaultResource" <!--this-->
      android:layout_width="match_parent"
      android:layout_height="match_parent">

But this is the easy solution, 'cause you make missing the resourse in Android.

I resolve this with file system option. If Android tell you about missing resourse meaning some thing is missing and you should replenish that.

you should be go to \app\src\main\res

maybe: right click in file's missing folder, show in Exporer,and go back to \app\src\main\res

You should be find

/layout

/layout-normal

/layout-large

/some more folders

You should be find where do the files is missing. In my case that's missing in /layout

Solution 9 - Android

In my case, this issue was caused by Uppercase letter. Wrong chars like "-" can also cause the issue. I changed the name from Activity_disease.xml to activity_disease.xml and the issue fixed.

Solution 10 - Android

Nothing worked for me like rebuilding the project or Invalidating the cache. In my case closing and reopening Android studio solved the problem.

Solution 11 - Android

Press- 'ctrl+A' --> 'ctrl+x' --> 'ctrl+v') this does not change anything but apparently solves the errors.

Solution 12 - Android

I solved this issue by just syncing project with gradle

Solution 13 - Android

I had copied the xml files in the folder using Windows Explorer. It seems to have caused an encoding issue. After deleting the files and coping them inside Android Studio, the problem was resolved.

Solution 14 - Android

In my case it seems that Google used to expect (or at least accept) different names between different layouts; I had a time_dialog.xml and a time_dialog_landscape.xml. Renaming the latter to time_dialog.xml fixed the problem.

Solution 15 - Android

For me the following steps made it work:

  1. Cut all the code out of the page (ctrl+A+X for windows)
  2. Paste the code back.

Solution 16 - Android

I had an issue after copy/pasting code into an XML layout file, but I fixed it by just manually creating the file. Very strange, since the code was exactly the same, but somehow it fixed this issue. I did try restarting and doing the "File => Invalidate Caches / Restart => Invalidate and Restart" fix, but the issue was only fixed by manually recreating the file.

Solution 17 - Android

Note that when you are using different versions of layout like (Large/Small/Nornal) then that case you have to same main layout folder. like this way

enter image description here

Solution 18 - Android

Similarly to the previous post, I had to rename the resource. I created it initially by copy-pasting an .xml file in the project explorer. Confusingly this had the same name in the explorer but with a land dimmed attribute associated with the layout.

My solution was to go into the file system and manually move the file from the layout-land to layout folder

Solution 19 - Android

For me it occured because I had accidentally named the file with a spacebar rather than underline, i.e fragment_item summary.xml rather than fragment_item_summary.xml.

Solution 20 - Android

This issue seems to be happening because studio or compiler is not able to find the resource file inside the base layout folder. To solve the problem you might need to create the file into different layout folders. If you are using layout folders v21, v25 etc. folders for designing layouts for different target devices then you also might need to place your resource files there too.

Solution 21 - Android

In my case this warning appeared due to "wrong" character (dot) used in value name:

<dimen name="dp.divider.xlarge">24dp</dimen>

Removing dots (right click on a name, then Refactor-Rename in Android Studio) resolved the problem.

Solution 22 - Android

Late to the party but My case is different from above.

I just renamed the resource and it started working.

Actually my resource name was ic_menu_black_24dp.xml so it was conflicting with the android's menu resource.

Solution 23 - Android

What worked for me is to remove the id attribute

android:id="@+id/[id same as filename]"

from the layout resource.

Solution 24 - Android

(1) Delete the original layout.

(2) Add the layout again.

Step-1

Step-2

Solution 25 - Android

What solved it for me:

In Android Studio, right-click on the filename in the layout directory, and choose Reformat code, with no special tickbox selected on the next screen.

Not sure what exactly goes on under the hood here, but that worked.

Solution 26 - Android

In my case the same error was showing because layout-land file and layout filename was different.

My Case: layout-land -> my_layout_land layout -> my_layout

I solved it by making both filenames the same. Because if you are using layout-land and you have a file in layout-land then you must have a file in layout folder also.

Solution 27 - Android

Placing tools:ignore="MissingDefaultResource" in the screen layout description solved it for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionL KempView Question on Stackoverflow
Solution 1 - AndroidvovahostView Answer on Stackoverflow
Solution 2 - AndroidItounView Answer on Stackoverflow
Solution 3 - AndroidZiohView Answer on Stackoverflow
Solution 4 - AndroidAyoub AnbaraView Answer on Stackoverflow
Solution 5 - AndroidrmirabelleView Answer on Stackoverflow
Solution 6 - AndroidTravis CastilloView Answer on Stackoverflow
Solution 7 - AndroidGuilherme OliveiraView Answer on Stackoverflow
Solution 8 - AndroidWalter PalaciosView Answer on Stackoverflow
Solution 9 - AndroidDani NuñezView Answer on Stackoverflow
Solution 10 - AndroidRahulView Answer on Stackoverflow
Solution 11 - AndroidGopal MeenaView Answer on Stackoverflow
Solution 12 - AndroidmemresView Answer on Stackoverflow
Solution 13 - AndroidL KempView Answer on Stackoverflow
Solution 14 - AndroidJohn PerryView Answer on Stackoverflow
Solution 15 - AndroidVander IgView Answer on Stackoverflow
Solution 16 - AndroidoggynatorView Answer on Stackoverflow
Solution 17 - Androidpankaj kumarView Answer on Stackoverflow
Solution 18 - AndroidAndreiView Answer on Stackoverflow
Solution 19 - AndroidSaligiaView Answer on Stackoverflow
Solution 20 - AndroidrintuView Answer on Stackoverflow
Solution 21 - AndroidTahaView Answer on Stackoverflow
Solution 22 - AndroidAshish ShuklaView Answer on Stackoverflow
Solution 23 - AndroidRuudSiebView Answer on Stackoverflow
Solution 24 - AndroidliqiangView Answer on Stackoverflow
Solution 25 - AndroidRazvan_TK9692View Answer on Stackoverflow
Solution 26 - AndroidUjjawal KumarView Answer on Stackoverflow
Solution 27 - AndroidEarl AllenView Answer on Stackoverflow