'Android Studio says "androidx.drawerlayout.widget.DrawerLayout" was not found in the project or libraries, even though I already add it in the gradle

enter image description here

Also below is the code text from the same snippet that has been attached.

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


Solution 1:[1]

Try doing any of these methods:

  • Close your android project by going to File -> Close Project. And then import it again
  • If above option doesn't works for you then Go to File -> Invalidate Caches/Restart

If neither of them work the remove the dependency and add it again and tell me the build output when gradle sync finishes

Solution 2:[2]

It may possible that your studio cache is corrupted;

So

  • close your all project first; then
  • open your studio path in your C:\ Drive; for eg. it should like C:\Users\hp(Your_User_Name)\.AndroidStudio4.0\system\caches... Delete this caches folder.

Now start your project again, issue will gone now.

Hope this may help to someone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 REX
Solution 2 Bhoomika Patel