Wednesday, August 25, 2010

Android: Working with Library Projects

What is library projects?
- a development project that holds shared Android source code and resources

When should I create a project as library?
- if you have source code and resources that are common to multiple application projects

Why should I create a project as library?
- easier to maintain across different applications

What are the differences between standard and library project?
1. library project cannot be compiled directly to its own .apk
2. library project cannot reference other libraries

How to solve resource conflict between application and libraries?
1. conflicted resource with lower priority will be discarded
2. priority: application > library (priority of each library can be defined user)
3. use prefixes to avoid resource conflicts

How to create a library project?
1. create an android project
2. modify project properties
(1) Properties->Android
(2) check "Is Library" box
3. declare all components to be shared in manifest

How to referencing a library project from an application?
1. goto application project
2. modify project properties
(1) Properties->Android
(2) add project(s)
(3) use up/down to change priority of projects if necessary

3. add declarations of all components will be used from library in manifest
4. add library to build path (not mentioned in official document)
(1) Properties->Java BuildPath->Source
(2) link source
(3) rename folder if necessary

ref: http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject

No comments:

Post a Comment