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 the Package Explorer, right-click the dependent project and select Properties.
  2. In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
  3. Click Add to open the Project Selection dialog.
  4. From the list of available library projects, select a project and click OK.
  5. When the dialog closes, click Apply in the Properties window.
  6. Click OK to close the Properties window.

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.

 

Android如何引用其他工程_第1张图片

 

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 the Up and Down controls. 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 , and so on, as well as, and similar elements.

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

For example, the TicTacToeMain example application declares the library Activity GameActivity like this:

   ...        ...     android:name="com.example.android.tictactoe.library.GameActivity" />     ...   

 

 

按如下方法设置:

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. Android圆形水波纹按钮的实现(Ripple)
  2. 高级Android工程师进阶系列文章汇总
  3. android > 修改Android工程版本
  4. android开发_文本按钮 与 输入框
  5. title上左右按钮
  6. android studio 导入工程
  7. Android实现输入法弹出时把布局顶上去和登录按钮顶上去的解决方
  8. Android软件工程师之不归路
  9. android基础入门(二)——创建android工程

随机推荐

  1. Android(安卓)adb setuid提权漏洞的分析
  2. android 线程间通信
  3. android短彩信数据库设计(三)
  4. Android(安卓)API 中文 (54) —— Filterab
  5. android 零散笔记不定期更新 v16
  6. Android(安卓)1.5 1.6 2.0 2.1 2.2 2.3 3
  7. 简单的 Android(安卓)拍照并显示以及获取
  8. Android: Android(安卓)Architecture
  9. Android(安卓)应用程序的结构
  10. 用一个二维码做下载地址,自动区分是 ios