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

问题


After migrating from Eclipse to the new version of 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: It seems to a be an encoding issue. I had copied the xml files in the folder using Windows Explorer. After deleting the files and coping them inside Android Studio, the problem has been solved.


回答1:


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




回答2:


You can also try this :

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




回答3:


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




回答4:


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

you should add layout by default like thise:

enter image description here




回答5:


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




回答6:


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.




回答7:


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.




回答8:


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




回答9:


I just did Build > Clean Project




回答10:


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.




回答11:


I solved this issue by just syncing project with gradle




回答12:


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.



回答13:


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.




回答14:


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.




回答15:


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.




回答16:


What worked for me is to remove the id attribute

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

from the layout resource.




回答17:


(1) Delete the original layout land (2) add layout land again [step][1] [1]: https://i.stack.imgur.com/MyZr0.png

 [step][2]
  [2]: https://i.stack.imgur.com/GQQV5.png



回答18:


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.



来源:https://stackoverflow.com/questions/52547657/the-layout-layout-in-layout-has-no-declaration-in-the-base-layout-folder-erro


更多相关内容:请点击查看