Android如何引用其他工程

简介:

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.

 

 

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 <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, the TicTacToeMain example application declares the library Activity GameActivity like 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的代码等资源都已经引入进来。










本文转自 sw840227 51CTO博客,原文链接:http://blog.51cto.com/jerrysun/804910,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
Java 关系型数据库 数据库
Android App连接真机步骤与APP的开发语言和工程结构讲解以及运行实例(超详细必看)
Android App连接真机步骤与APP的开发语言和工程结构讲解以及运行实例(超详细必看)
38 0
|
7月前
|
存储 传感器 定位技术
《移动互联网技术》 第四章 移动应用开发: Android Studio开发环境的使用方法:建立工程,编写源程序,编译链接,安装模拟器,通过模拟器运行和调试程序
《移动互联网技术》 第四章 移动应用开发: Android Studio开发环境的使用方法:建立工程,编写源程序,编译链接,安装模拟器,通过模拟器运行和调试程序
85 0
|
2月前
|
监控 Devops Java
大型IM工程重构实践:企业微信Android端的重构之路
本文将探讨我们在大型IM工程实践中采用的一些行之有效的重构方法和实例,以及如何让一个大型软件系统持续保持活力。
49 0
|
3月前
|
Java Android开发
[Android AIDL] --- AIDL工程搭建
[Android AIDL] --- AIDL工程搭建
22 0
|
7月前
|
测试技术 开发工具 数据库
《移动互联网技术》第十一章 Android应用工程案例: 掌握Android系统的需求分析和设计以及 Android项目的程序测试和版本管理方法
《移动互联网技术》第十一章 Android应用工程案例: 掌握Android系统的需求分析和设计以及 Android项目的程序测试和版本管理方法
75 0
|
9月前
|
XML Java Android开发
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
|
9月前
|
数据安全/隐私保护 Android开发
uniapp vue3版本 Android 引用 jsencrypt加密库 报错问题 “default“ is not exported by,解决方法
uniapp vue3版本 Android 引用 jsencrypt加密库 报错问题 “default“ is not exported by,解决方法
850 0
|
10月前
|
Android开发
Android 开发引用 okio 依赖之后无法运行main方法的坑
Android 开发引用 okio 依赖之后无法运行main方法的坑
75 1
|
存储 缓存 Java
Android C++系列:JNI引用管理
在 Native 代码中有时候会接收 Java 传入的引用类型参数,有时候也会通过 NewObject 方法来创建一个 Java 的引用类型变量。在编写 Native 代码时,要注意这个代表 Java 数据结构类型的引用在使用时会被 GC 回收的可能性。
107 0
|
Android开发
android和Flutter的混合工程Demo
Flutter和Android混合工程的启动逻辑与纯Flutter应用程序的启动逻辑略有不同。在混合工程中,您需要在Android项目中添加一些额外的代码来启动Flutter引擎并加载Flutter代码。以下是整个app的启动逻辑的详细解释
android和Flutter的混合工程Demo