recoup8063
recoup8063

Reputation: 4280

Android DrawerLayout must be declared Error

I am making a simple Android app and I wanted to make a DrawerLayout menu. When I went to use it, it said that drawer layout must be declared. I checked my SDK manager and the android support jar is installed and up to date.
enter image description here
I tried uninstalling and re-installing but that did not help. I also tried creating a new project and that did not work.
Code:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/>

</android.support.v4.widget.DrawerLayout>



Error:

Element android.support.v4.widget.DrawerLayout must be declared



Other Info:
Minimum API: 7
Build API: 18
IDE: Android Studio(Using Gradle)
Android Studio Build Number: AI-132.863010(Up to date) I am now using Android studio 3.0

Upvotes: 1

Views: 3601

Answers (1)

nana
nana

Reputation: 4481

You need to add the support library to your libraries.

If you are using Gradle, just add:

dependencies {
    ...
    compile "com.android.support:support-v4:18.0.+"
}

to your build.gradle file.

If not using gradle to take care of your dependencies:
Press Ctrl + Alt- Shift +S (Project Structure IconProject Structure).

Then Libraries > New Project Library > Java

Locate the JAR I am sure you copied to your ./libs folder already and you should be done.
or use this shortcut:
just copy android-support-v4.jar to YourProject/libs, right click on the JAR from Android Studio and choose Add as Library

Edit:
As of Android Studio 0.3 You shouldn't have to manually edit the gradle file, you can just add the libraries in project structure.

Upvotes: 4

Related Questions