12

I'm trying to import the classes required to use the new "Navigation Drawer" from Android http://developer.android.com/design/patterns/navigation-drawer.html#ImpactOnNav

DrawerLayout: http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

ActionBarDrawerToggle: http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

The import android.support.v4.widget.DrawerLayout cannot be resolved The import android.support.v4.app.ActionBarDrawerToggle cannot be resolved

I have updated the libraries to the latest version but still these classes are not recognized.

Eric Bergman
  • 1,453
  • 11
  • 46
  • 84
  • 1
    Did you update the copy of the JAR in the project? Or did you just run the SDK Manager? The SDK Manager updates what's in your SDK, not the JARs in `libs/` in your project(s). – CommonsWare Jun 11 '13 at 14:21
  • @CommonsWare I just ran the SDK manager, How do I update the JARs in libs? – Eric Bergman Jun 11 '13 at 14:25

3 Answers3

13

How do I update the JARs in libs?

I usually do it by copying the file. You will find the JARs inside $ANDROID_SDK/extras/android/support, where $ANDROID_SDK is wherever your Android SDK is installed.

If you use Eclipse, if you copy this at the filesystem level, and Eclipse is open, press <F5> with the project highlighted in Package Manager so Eclipse picks up the changes. Easier is to drag it out of the SDK and drop the JAR into libs/ right in Eclipse, which will both update the filesystem and let Eclipse know about the change.

It's possible that the Eclipse option to add the JARs (right-click over the project, then choose Android Tools > Add Support Library... from the context menu) will also do this. That particular approach doesn't work for me due to some peculiarities with my development environment.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the detailed explanation, although I had to right click on the android-support-v13.jar file in the project /libs folder and select "Add to Build Path". Thank you. – Eric Bergman Jun 11 '13 at 14:41
  • 1
    @EricBergman: "Add to Build Path" is not the right answer. Having it in `libs/` is sufficient, though on R22 and higher you also need to fix up the Order and Export portion of your build path: http://stackoverflow.com/questions/16596969/libraries-do-not-get-added-to-apk-anymore-after-upgrade-to-adt-22/16596990#16596990 – CommonsWare Jun 11 '13 at 14:56
  • you are right "Add to Build Path" caused a lot of errors in my project thanks for the advice it works fine now. – Eric Bergman Jun 11 '13 at 15:06
12

Copy the support jar from the Android SDK into your libs folder. Should be in <ANDROID SDK FOLDER>\extras\android\compatibility\v13.

Femi
  • 64,273
  • 8
  • 118
  • 148
5

In android studio, I found that adding dependencies solved the problem.

In the file menu find project structure. Under 'app', look for the dependencies tab. Click the green plus at the right hand side. Select library dependency.

I added both support-v4 and support-v13.

0th
  • 51
  • 1
  • 1