2014-11-04 37 views
4

人們說,他們是相同的,但在developer siteappcompat_v7和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?

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

餵我以你的經驗

回答

2

android-support-v7-appcompat.jar是一個JAR文件,僅包含編譯的Java類。 appcompat_v7是一個庫項目,其中包含以前的JAR文件,沒有實際的源代碼和大量資源(佈局,圖像,& c)。

appcompat-v7的特定情況下,您需要需要以使用庫項目,因爲它包含必要的UI資源。

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

請注意,差異主要適用於Eclipse(其中包含資源的庫必須作爲項目導入,而其他庫可以只放在libs文件夾中)。使用Android Studio/gradle,這一切都由構建系統處理,因此兩者的過程都是相同的。這在Support Library Setup文檔中有很好的解釋。

0

生成appcompat_v7包含了Android的支持-V7-程序兼容性庫,具有一定的資源一起。如果你讓Eclipse產生你的主題和佈局,他們會引用appcompat_v7項目中的資源,如果沒有它,你的項目將無法建立。我從來沒有遇到過只需要沒有資源的庫的情況,但是如果您想將新的支持庫功能合併到現有項目中,您可能會遇到這種情況。

+0

所以你鼓勵我改用android-support-v7-appcompat? – Lana 2014-11-04 19:54:37

+0

@Lana如果您的項目需要它包含的資源,請使用appcompat_v7,如果不需要,請使用android-support-v7-appcompat。 – 2014-11-04 20:29:43

+0

感謝您的回答 – Lana 2014-11-05 04:35:02

相關問題