Home » Android » How to add Android Support v7 libraries in eclipse?

How to add Android Support v7 libraries in eclipse?

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I add Android Support v7 libraries in eclipse? For example how do I add CardView to an eclipse android project?

Note: This was a self answer question, so no need to waste your time making an answer. Of course, if you have anything to add, please do.

How to&Answers:

From: https://developer.android.com/tools/support-library/setup.html#libs-with-res

I know this looks like a lot of steps, but in reality it’s just very broken down and only takes two minutes

To add a Support Library with resources (such as v7 cardview) to your application project using Eclipse:

Create a library project based on the support library code:

  • Make sure you have downloaded the Android Support Library using the SDK Manager.

  • Create a library project and ensure the required JAR files are included in the project’s build path:

  • Select File > Import.

  • Select Existing Android Code Into Workspace and click Next.

  • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the cardview project, browse to <sdk>/extras/android/support/v7/cardview/.

  • Click Finish to import the project. For the v7 cardview project, you should now see a new project titled android-support-v7-cardview.

  • In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the v7 cardview project, add the android-support-v7-cardview.jar file to the build path. (Depending on your setup, Eclipse may have done this four you already.)

  • Right-click the library project folder and select Build Path > Configure Build Path.

  • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the cardview project requires you to export the android-support-v7-cardview.jar file. (Depending on your setup, Eclipse may have done this four you already.)

  • Uncheck Android Dependencies.

  • Click OK (or Apply and Close) to complete the changes.

You now have a library project for your selected Support Library that you can use with one or more application projects.

Now add the library to your application project:

  • In the Project Explorer, right-click your project and select Properties.

  • In the category panel on the left side of the dialog, select Android.

  • In the Library pane, click the Add button.

  • Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-cardview.

  • In the properties window, click OK (or Apply and Close).

For some libraries, you will get error messages such as

No resource found that matches the given name ‘android:Widget.Material.ActionButton’. styles_base.xml/appcompat_v7/res/values-v21

If that happens, record the highest API level you are seeing in those error messages (v21 in the example above). Then, in the properties of your library project, go to Android and set the target API to that level (or a higher one), then clean your projects.

Answer:

This is what worked for me. (Using the same CardView example from above)

  1. Import CardView into the workspace:
    1. Click on File, then click on Import.
    2. Expand the Android folder, and select Existing Android Code into Workspace, then click on Next >.
    3. Click on Browse beside the Root Directory text input, and select the CardView project folder in (Android SDK Install Location) > extras > android > support > v7 > cardview
  2. Right click the CardView project, click Properties, then select Android from the list on the left.
  3. Check Is Library checkbox, and click Apply.
  4. In your project, right click and click on Properties, then select Android from the list on the left, and click Add.
  5. Your imported CardView project will be listed there. Select the CardView project, then click OK, and click Apply.

Now the library is imported.

PS: I tried I’m_With_Stupid’s answer, and while trying to add the library project to my project, it was not listed there.
I did not have to uncheck Android Dependencies, etc. It might work in some other situation, I guess.