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.

adt或eclipse中Android工程如何互相引用

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. 2012年全国最新Android开发工程师薪资水平调查分析
  2. Android入门教程(三)之----------> 导入现有Android工程
  3. Android工程中R.java文件的重新生成——注意资源文件的错误
  4. 【安卓开发】Facebook工程师是如何改进他们Android客户端的
  5. android 工程中重新生成gen文件夹或R.java 文件

随机推荐

  1. Jenkins奇技淫巧 — 第一次实战篇(Androi
  2. 五大Android布局方式浅析
  3. 【Android】Ripple使用总结及ClickableSp
  4. android 微信支付 简单实用
  5. Android为apk重新签名
  6. android 通讯录中贾(jia|gu)处理
  7. 【Android开发 蓝牙连接状态】Android实
  8. Android(安卓)AsyncTask和Handler对比
  9. android源码下载方法 批量下载 基于windo
  10. android service与activity交互的方试