Import Support V4 and V7 in Android projects

Source: Internet
Author: User
Tags android sdk manager

Google offers a package of Android support Library packages to ensure compatibility with high-version SDK development, that is, when we develop with 4.x, we can use some features of the higher version, such as Fragement, in the 1.6 version. Viewpager, below, briefly explain the differences between these versions:

Android Support V4: This package is designed to take care of 1.6 and later, this package is the most widely used, Eclipse new project, when the default comes with.

Android Support V7: This package is designed to take care of 2.1 and above, but does not include lower, so if you do not consider 1.6, we can add this package, in addition to note that V7 is to rely on V4 This package, that is, Two must be included at the same time.

Android Support V13 : This package is designed for Android 3.2 and later, generally we are not used, tablet development can be used.


There is such a problem:

When developing ADT New project, will automatically help you to add V4.jar bindings to your project, but you can not view the source of V4.jar, how to see the source code?

Then, look for the jar package under/EXTRAS\ANDROID\SUPPORT\V4 in the directory of the SDK and add it to it. Finally, you can follow the previous steps to bind the source code, right-click Jar package, attach Sourch file source files entered, the location of the source file is selected.

First, download the support Library

Method 1: Right-click project → select Android Tools→add support Library ...

Method 2:

Get the support Library from the SDK Manager:

1. Open the Android SDK Manager

2. In the SDK Manager window, scroll to the end of the package list, locate the extra folder, and open the folder to display its contents if needed.

3. Select the Android support Library project.

Note: If you are using Android Studio development, select and install the Android support repository project instead of the Android Support Library project.

4. Click the Install packages button.

When the download is complete, the SDK installs the support library file into your existing Android SDK directory. The library file is located in the following subdirectory of the SDK: <sdk>/extras/android/support/directory.

Second, add V4 Compatibility Pack (V4 Appconpat)
    1. Make sure you have downloaded the Android support Library using SDK Manager .
    2. Create a libs/directory in the root directory of your project .
    3. Copy the jar file from your Android SDK installation directory (for example, <sdk>/extras/android/support/v4/android-support-v4.jar) to your project's libs/directory.
    4. Right-click on the jar file and choose Build path > Add to build Path.
Third, add V7 Compatibility Pack (V7 Appconpat)

Create a library project based on the Support library code:

    1. Make sure that you have downloaded the Android support Library using SDK Manager.
    2. Create a library project and ensure that the required jar files are included in the project's build path:
      1. Select File > Import.
      2. Select Existing Android Code into Workspace and click Next.
      3. Browse the SDK installation directory and enter the support library directory. For example, if you want to add a AppCompat project, browse <sdk>/extras/android/support/v7/appcompat/.
      4. Click Finish to introduce the project. For the V7 AppCompat project, you will see a new project titled Android-support-v7-appcompat .
      1. In the new project, expand the libs/folder, right-click each of the. jar files, and select build path > Add to build Path. For example, when you create a V7 AppCompat project, both the Android-support-v4.jar and Android-support-v7-appcompat.jar files are added to the build path.
      2. Right-click on the Library project folder and choose Build path > Configure build Path.
      3. In the Order and export option, tick the. jar file that you just added to the build path, and these files become available to the project and depend on the library project. For example, the AppCompat project requires both Android-support-v4.jar and Android-support-v7-appcompat.jar files to be exported.
      4. Remove the checkmark on the Android Dependencies .
      5. Click OK to complete the setup

Now that you have a library project with the support library of your choice, you can take advantage of this support library in one or more application projects.

Now we're going to add the library to the application engineering (the project that needs to join the support library):

    1. Right-click your project in the project browser and select Properties.
    2. In the category panel on the left, select Android.
    3. In the Library panel, click Add.
    4. Select the library item and click OK. For example, the AppCompat item is displayed as Android-support-v7-appcompatin the list.
    5. In the Properties window, click OK.

Problems encountered:

1, Java.lang.noclassdeffounderror:android.support.v7.appcompat.r$attr

This problem is due to the fact that the app did not find the corresponding V7 compatibility package at run time, please add V7 Compatibility Pack (V7 Appconpat) in the reference article

2. Java.lang.IllegalStateException:You need to use a theme.appcompat Theme (or descendant) and this activity.

After completing the 1,3 steps mentioned above, modify Android:theme to @style/theme.appcompat

Import Support V4 and V7 in Android projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.