Setting up a Library Project
来源:互联网 发布:天刀成男捏脸数据 编辑:程序博客网 时间:2024/05/16 17:07
Setting up a Library Project
A library project is a standard Android project, so you can create a new one in the same way as you would a new application project.
When you are creating the library project, you can select any application name, package, and set other fields as needed, as shown in figure 1.
Next, set the project's properties to indicate that it is a library project:
- In the Package Explorer, right-click the library project and select Properties.
- In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
- Select the "is Library" checkbox and click Apply.
- Click OK to close the Properties window.
The new project is now marked as a library project. You can begin moving source code and resources into it, as described in the sections below.
You can also convert an existing application project into a library. To do so, simply open the Properties for the project and select the "is Library" checkbox. Other application projects can now reference the existing project as a library project.
Creating the manifest file
A library project's manifest file must declare all of the shared components that it includes, just as would a standard Android application. For more information, see the documentation for AndroidManifest.xml.
For example, the TicTacToeLib example library project declares the Activity GameActivity
:
<manifest> ... <application> ... <activity android:name="GameActivity" /> ... </application></manifest>
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:
- In the Package Explorer, right-click the dependent project and select Properties.
- In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
- Click Add to open the Project Selection dialog.
- From the list of available library projects, select a project and click OK.
- When the dialog closes, click Apply in the Properties window.
- 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.
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 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> ... <activity android:name="com.example.android.tictactoe.library.GameActivity" /> ... </application></manifest>
For more information about the manifest file, see the documentation for AndroidManifest.xml.
- Setting up a Library Project
- Setting Up a Selenium-WebDriver Project
- CocosBuilder用户手册中文版:2. Setting up a New Project
- Windows下Setting Up a Project(建立一个工程)
- Five suggestions for setting up a Go project
- Setting up a new Typescript 1.9 and React project
- Setting Up a RequestQueue
- Setting Up a Maven Repository
- Setting up a LAMP stack
- Setting up a LAMP stack
- Setting up a Database Connection
- Setting up a Storm Cluster
- Setting up a Custom Membership Provider
- A great article about setting up exim
- Setting Up a Telnet Server in Ubuntu
- Setting up a new remote git repository
- Setting up a Device for Development
- Setting up SSH for a Hadoop cluster
- 实施ERP过程中必须注意的“后天条件”
- Windows Mobile引路蜂地图开发示例:IP地址查询
- 高通Android平台下关于display部分的几个关键问题
- iPad iPhone程序增加和删除启动画面
- 企业实施ERP前必做的三件事
- Setting up a Library Project
- 案例:代码走查
- http://blog.sina.com.cn/s/blog_4e6dffee0100hid1.html
- Windows Mobile引路蜂地图开发示例:地址反编码
- android 中layer-list的用法
- go语言之hello world
- MySQL加密和解密
- 分类显示和改变外观
- 解决SAXParseException: Premature end of file