簡體   English   中英

appcompat_v7和android-support-v7-appcompat之間的區別?

[英]Difference between appcompat_v7 and android-support-v7-appcompat?

人們說它們是相同的但是它們在開發者網站中所說的不同情況下使用

1 - 添加沒有資源的庫

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 - 使用資源添加庫

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.

我應該何時使用appcompat_v7(自動生成項目)以及何時使用android-support-v7-appcompat?

在這種情況下,程序員需要在項目中添加資源庫嗎?

請用我的經驗喂我

android-support-v7-appcompat.jar是一個JAR文件,只包含已編譯的Java類。 appcompat_v7是一個庫項目,它包含以前的JAR文件,沒有實際的源代碼,以及許多資源(布局,圖像和c)。

appcompat-v7的特定情況下,您需要使用Library Project,因為它包含必要的UI資源。

其他庫(例如v7 MediaRouter或v7 Palette)不包含這些資源,因此可以直接使用JAR文件。

請注意,差異主要適用於Eclipse(其中包含資源的庫必須作為項目導入,而其他庫只能放在libs文件夾中)。 使用Android Studio / gradle,這全部由構建系統處理,因此兩者的過程相同。 支持庫安裝文檔中對此進行了詳細說明。

生成的appcompat_v7包含android-support-v7-appcompat庫以及一些資源。 如果您讓Eclipse生成主題和布局,他們將引用appcompat_v7項目中的資源,如果沒有它,您的項目將無法構建。 我從來沒有遇到過只需要沒有資源的庫的情況,但是如果你想在現有項目中加入新的支持庫功能,也許你可能會這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM