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>  ...  <activityandroid:name="com.example.android.tictactoe.library.GameActivity"/>  ... </application></manifest>

按如下方法设置:

1. 假设要引用的android工程叫LibProject,引入到的工程叫MainProject;

2. 设置LibProject,右键->Properties->Android,将Is library项选中,然后Apply;

3. 设置MainProject,右键->->Properties->Android, 在Library中,点击Add按钮,将LibProject工程加入,Apply即可。

设置完成后,在MainProject工程中能看到LibProject的代码等资源都已经引入进来。

本文转载自:http://blog.csdn.net/johnnywsd/article/details/6845451

更多相关文章

  1. [置顶] TabHost ~ 仿微信底部菜单
  2. android判断网络状态
  3. Android(安卓)5.0WebView选择本地文件
  4. android Intent Flags详解
  5. Android(安卓)如何设置网关和路由
  6. LinearLayout布局中将一个控件放在屏幕的最下方-Android
  7. Android视频录制
  8. android全屏设置
  9. android Intent Flags详解

随机推荐

  1. sqlserver实现更改字段名
  2. 浅谈SQLServer的ISNULL函数与Mysql的IFNU
  3. 深入SQLServer中ISNULL与NULLIF的使用详
  4. 探讨:如何查看和获取SQL Server实例名
  5. 使用SQL Server判断文件是否存在后再删除
  6. 解析如何在sqlserver代理中配置邮件会话
  7. 深入sql server 2005 万能分页存储过程的
  8. 在SQL Server 2005中创建CLR存储过程的详
  9. SQL Server 2005 创建简单的存储过程--总
  10. 图解SSIS批量导入Excel文件的实现方法