You can do that in atleast two ways as I know. This answer assumes that you are using Eclipse.
- Mark project B as a library project and add it as a dependency through the
Android
tab in the project properties. - Export the project-B into a library JAR and add the jar into the
\libs
folder and then to the build path of Project-A
In the first case, you have the opportunity to make changes to the library project and avail the latest updates in your dependent project after a clean up. To use this method, right click on the project folder, and select properties. The in the Android tab on the left, tick the check-box which says Is Library
. Once this is done, go to project A, which is the dependent project and reach the Android tab through the same menu. Then under Library, click Add
and select Project-B as a dependency. Clean up both the projects and build them. You are ready to go.
In the second case, click on Project-B and go through File -> Export -> Java -> Jar File
. Then choose a destination folder and generate a jar. Once the jar is created, copy it into the project's \libs
folder. You may optionally add this into the build path as well, but in normal case it will already be added once you copy it there.