JavaEar 专注于收集分享传播有价值的技术资料

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.

7个回答

    最佳答案
  1. In my case closing and reopening Android studio solved the problem. Rebuilding project didn't have any effect.

  2. 参考答案2
  3. You can also try this :

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

    screenshot

  4. 参考答案3
  5. 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.

  6. 参考答案4
  7. 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

  8. 参考答案5
  9. 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

  10. 参考答案6
  11. 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. Seems likely to be an IDE bug.

  12. 参考答案7
  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.