在Android应用开发过程中,只要涉及两个或以上人的开发,就需要考虑分工和代码的组织和重用问题。
代码重用有三种方式:
1.APK;
2.JAR;通过Libs/ 和Build path集成,缺点是不能包含Android的资源;
3. Android Library Project;
三种方式的优劣分析,主要是JAR方式是以Binary方式重用的经典方式;
详见:http://www.slideshare.net/commonsguy/android-reuse-models
Android Library Project方式:
如果你有多个Android项目是共同的源代码和资源,你可以将它们添加到库项目,因此,它是跨应用程序和版本更容易维护。下面是一些常见的情况下,您可以使用库项目:
- 如果您正在开发多个相关的应用程序,使用一些相同的部件,您将冗余组件出各自的应用项目,并创建一个单一的,可重复使用相同的组件库中的项目组。
- 如果您要创建一个应用程序中存在的免费和付费两种版本。你移动到库项目中是常见的两个版本的应用程序的一部分。两个相关的项目,有着各自不同的包名,将引用库项目,只提供应用程序两个版本之间的差异。
I have the instructions in _The Busy Coder's Guide to Advanced Android
Development_ (http://commonsware.com/AdvAndroid), though the
instructions are new enough that none of my free versions have them.
Quoting some of the instructions from the current edition:
"You can create a binary-only library project via the following steps:
1. Create an Android library project, with your source code and such –
this is your master project, from which you will create a version of
the library project for distribution
2. Compile the Java source (e.g., ant compile) and turn it into a JAR file
3. Create a distribution Android library project, with the same
resources as the master library project, but no source code
4. Put the JAR file in the distribution Android library project's libs/
directory
The resulting distribution Android library project will have everything a
main project will need, just without the source code."
Android library projects: Use common code in multiple apps
Android native libraries modularity / code reuse
The Busy Coder's Guide to Advanced Android Development