Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Android Support v7 libraries in eclipse?

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.

like image 790
I'm_With_Stupid Avatar asked Nov 12 '14 03:11

I'm_With_Stupid


People also ask

How do I add the v7 Appcompat support library?

In the Properties window, select the "Android" properties group at left and locate the Library properties at right. Select /path/to/appcompat/ and Click Remove. Click Add to open the Project Selection dialog. From the list of available library projects, select v7 appcompat library and click OK.

What is v4 and v7 in Android?

difference. v4 has largest set of API's than others like App component, User Interface Feature, data handling ,network connectivity and utilities. v7 provided specfic feature sets that can be included in your app independently.

What is Appcompat v7 in Android?

Android AppCompat Library V7 The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later. License.

What are support libraries in Android?

The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs. Each Support Library is backward-compatible to a specific Android API level.


2 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.

like image 75
I'm_With_Stupid Avatar answered Oct 25 '22 13:10

I'm_With_Stupid


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.

like image 37
Siva Avatar answered Oct 25 '22 14:10

Siva