简体   繁体   中英

Difference between appcompat_v7 and android-support-v7-appcompat?

People say they are the same but they are used in different situations as said in developer site

1-Adding libraries without resources

To add a Support Library without resources to your application project:

Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.

2-Adding libraries with resources

To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:

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 appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
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 the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
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 appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK 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.

when should I use appcompat_v7 (which is generated with the project automatically ) and when to use android-support-v7-appcompat ?

In which case the programmer needs to add library with the resources in the project ?

please feed me with your experience

android-support-v7-appcompat.jar is a JAR file, containing only compiled Java classes. appcompat_v7 is a Library Project, which contains the previous JAR file, no actual source code, and a great many resources (layouts, images, &c).

In the particular case of appcompat-v7 , you need to use the Library Project, since it contains necessary UI resources.

Other libraries (such as v7 MediaRouter or v7 Palette) do not contain these resources, and therefore the JAR file can be used directly.

Note that the difference applies mainly to Eclipse (in which libraries with resources must be imported as a project while the others can be just placed in the libs folder). With Android Studio/gradle this is all handled by the build system and therefore the procedure is the same for both. This is well explained in the Support Library Setup documentation.

The generated appcompat_v7 contains the android-support-v7-appcompat library, along with some resources. If you let Eclipse generate your themes and layouts, they will refer to the resources in the appcompat_v7 project and your project won't build without it. I've never encountered a situation where I needed only the library without the resources, but perhaps you might if you wanted to incorporate a new support library feature into an existing project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM