Referencing a library project

If you are developing an application and want to include the shared code or resources from a library project, you can do so easily by adding a reference to the library project in the application project's Properties.

To add a reference to a library project, follow these steps:

  1. In thePackage Explorer, right-click the dependent project and selectProperties.
  2. In thePropertieswindow, select the "Android" properties group at left and locate theLibraryproperties at right.
  3. ClickAddto open theProject Selectiondialog.
  4. From the list of available library projects, select a project and clickOK.
  5. When the dialog closes, clickApplyin thePropertieswindow.
  6. ClickOKto close thePropertieswindow.

As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.

Figure 2 shows the Properties dialog that lets you add library references and move them up and down in priority.

Figure 2.Adding a reference to a library project in the properties of an application project.

If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by selecting a library and using theUpandDowncontrols. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.

Declaring library components in the the manifest file

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any<activity>,<service>,<receiver>,<provider>, and so on, as well as<permission>,<uses-library>, and similar elements.

Declarations should reference the library components by their fully-qualified package names, where appropriate.

For example, theTicTacToeMainexample application declares the library ActivityGameActivitylike this:

<manifest>  ...  <application>    ...    <activity android:name="com.example.android.tictactoe.library.GameActivity" />    ...  </application></manifest>

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)文字倾斜
  2. android 定时任务的几种实现方式
  3. 一些android porting 例子
  4. 禁止应用获取手机信息
  5. Android程序运行中动态加载Lib的方法(一)
  6. Android真机调试——远程主机强迫关闭了
  7. Android Google Map实例 - 不同的图标标
  8. 【摘录】Android 2.3状态栏中添加menu,hom
  9. 日拱一卒(五十九)
  10. Android客户端和服务器端数据交互的第一