Managing Projects from Eclipse with ADT

In this document

  1. Creating an Android Project  创建可运行项目
  2. Setting up a Library Project   创建lib项目
  3. Referencing a Library Project 如何引用一个lib项目

See also

  1. Testing from Eclipse with ADT

Eclipse and the ADT plugin provide GUIs and wizards to create all three types of projects (Android project, Library project, and Test project):

  • An Android project contains all of the files and resources that are needed to build a project into an .apk file for installation. You need to create an Android project for any application that you want to eventually install on a device.
  • You can also designate an Android project as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device.
  • Test projects extend JUnit test functionality to include Android specific functionality. For more information on creating a test project, see Testing from Eclipse with ADT.

Creating an Android Project


The ADT plugin provides a New Project Wizard that you can use to quickly create a new Android project (or a project from existing code). To create a new project:

  1. Select File > New > Project.
  2. Select Android > Android Application Project, and click Next.
  3. Enter the basic settings for the project:
    • Enter an Application Name. This name is used as the title of your application launcher icon when it is installed on a device.
    • Enter a Project Name. This text is used as the name of the folder where your project is created.
    • Enter a Package Name. This class package namespace creates the initial package structure for your applications code files and is added as the package attribute in your application's Android manifest file. This manifest value serves as the unique identifier for your application app when you distribute it to users. The package name must follow the same rules as packages in the Java programming language.
    • Select a Minimum Required SDK. This setting indicates the lowest version of the Android platform that your application supports. This value sets the minSdkVersion attribute in the <uses-sdk> element of your manifest file.
    • Select a Target SDK. This setting indicates the highest version of Android with which you have tested with your application and sets the targetSdkVersion attribute in your application's' manifest file.

      Note: You can change the target SDK for your project at any time: Right-click the project in the Package Explorer, select Properties, select Android and then check the desired Project Build Target.

    • Select a Compile With API version. This setting specifies what version of the SDK to compile your project against. We strongly recommend using the most recent version of the API.
    • Select a Theme. This setting specifies which standard Android visual style is applied to your application.
    • Click Next.
  4. In the Configure Project page, select the desired settings and click Next. Leave the Create activity option checked so you can start your application with some essential components.
  5. In the Configure Launcher Icon page, create an icon and click Next.
  6. In the Create Activity page, select activity template and click Next. For more information about Android code templates, see Using Code Templates.
  7. Click Finish and the wizard creates a new project according to the options you have chosen.

Tip: You can also start the New Project Wizard by clicking the New  icon in the toolbar.

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.

To create a new library project:

  1. Select File > New > Project.
  2. Select Android > Android Application Project, and click Next.
  3. Enter the basic settings for the project, including Application NameProject NamePackage Name, and SDK settings.
  4. In the Configure Project page, select the Mark this project as a library option to flag the project as a library.
  5. Set the other options as desired and click Next.
  6. Follow the instructions to complete the wizard and create a new library project.

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, as shown in the figure below.

Figure 1. Marking a project as an Android library.

To set the a project's properties to indicate that it is a library project:

  1. In the Package Explorer, right-click the library project and select Properties.
  2. In the Properties window, select the Android properties group in the left pane and locate the Library properties in the right pane.
  3. Select the is Library check box and click Apply.
  4. Click OK to close the Properties window.

Once you create a library project or mark an existing project as a library, you can reference the library project in other Android application projects. For more information, see the Referencing a library project section.

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:

  1. Make sure that both the project library and the application project that depends on it are in your workspace. If one of the projects is missing, import it into your workspace.
  2. In the Package Explorer, right-click the dependent project and select Properties.
  3. In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
  4. Click Add to open the Project Selection dialog.
  5. From the list of available library projects, select a project and click OK.
  6. When the dialog closes, click Apply in the Properties window.
  7. 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 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.

用Eclipse+ADT创建可运行项目,创建lib项目,引用一个lib项目的更多相关文章

  1. vue 动态创建组件(运行时创建组件)

    function mountCmp (cmp, props, parent) { if (cmp.default) { cmp = cmp.default } cmp = Vue.extend(cmp ...

  2. Eclipse中对一个项目进行复制粘贴为一个新项目

    1:对目标项目执行右键,选择“Copy”,然后在空白处右键,选择“Paste”结果如下图: 2:右键新项目,点击Properties, 3:打开Navigator视图 4:打开.settings文件夹 ...

  3. 在Eclipse中配置Tomcat 创建和运行Servlet/JSP

    在Eclipse中配置Tomcat 创建和运行Servlet/JSP 步骤一:在Eclipse中配置Tomcat(注意下载Eclipse IDE for Java EE Developers) (1) ...

  4. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.3——用Eclipse ADT导出App

    问题: 想在一个已经存在的Eclipse ADT的项目中使用Gradle 解决方案: Eclipse ADT插件可以帮助生成Gradle文件 讨论: Eclipse的ADT插件是在2013年推出Gra ...

  5. 基于Grunt构建一个的项目

    没有搭建环境的,请参考<Grunt自动化构建环境搭建 >,搭建完成后 新建一个项目目录,这里建立一个“Demo”目录 运行CMD,并进入这个目录,运行 npm install grunt ...

  6. lz的第一个RN项目

    这是lz 成功在原有项目上集成的第一个ReactNative 项目. 参考官方网址: http://reactnative.cn/docs/0.43/integration-with-existing ...

  7. 3.第一个scrapy项目

    第一个scrapy项目 1. 创建scrapy项目 1.1 创建项目三剑客 这里的三剑客指的是:创建项目以及运行项目的三条命令 1.1.1 创建项目 scrapy stratproject 项目名称 ...

  8. 初学者如何吃透一个Java项目

    不少初学者朋友在学习Java过程中,会对着视频敲Java项目,其中遇到的BUG还能解决,但就是每次敲完一个项目,就感觉很空虚,项目里面的知识点感觉懂了但又好像没懂 这些朋友应该怎样才能掌握一个项目所用 ...

  9. [原]Jenkins(十四)---jenkins示例:admin管理所有项目,新建用户只能看部分项目

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. *如有错误,请指正 * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horiz ...

随机推荐

  1. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  2. wireshark常用的过滤命令

    我们使用wireshark抓包,却不知道如何分析这些包,也无法从海量的包中提取自己需要的数据,下面简单介绍下wireshark的过滤规则. 过滤源ip.目的ip.在wireshark的过滤规则框Fil ...

  3. 网页出现scanstyles does nothing in Webkit / Mozilla的解决方法

    今天ytkah要验证一些百度服务,那边的客服MM说她用ie浏览器打开网页出现"scanstyles does nothing in Webkit / Mozilla / Opera" ...

  4. MySQL查看表占用空间大小(转)

    MySQL查看表占用空间大小(转) //先进去MySQL自带管理库:information_schema //自己的数据库:dbwww58com_kuchecarlib //自己的表:t_carmod ...

  5. 小圣求职记B:总集篇

    1. 搜狐sohu 搜狐在正式招聘前邀请了部分应聘者到武汉研发中心开座谈会(因此简历尽量早投,机会多些),有研发的也有产品的,40人左右,座谈会期间介绍了搜狐汽车.北京研发中心.武汉研发中心和搜狐媒体 ...

  6. 就地交叉数组元素[a1a2b1b2]->[a1b1a2b2]

    问题描述: If [a1,a2,a3...,an,b1,b2...bn] is given input change this to [a1,b1,a2,b2.....an,bn] , solutio ...

  7. **app后端设计(10)--数据增量更新(省流量)

    在新浪微博的app中,从别的页面进入主页,在没有网络的情况下,首页中的已经收到的微博还是能显示的,这显然是把相关的数据存储在app本地. 使用数据的app本地存储,能减少网络的流量,同时极大提高了用户 ...

  8. HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数

    GTW likes function      Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...

  9. 妙味课堂——HTML+CSS(第四课)(二)

    单开一篇来讲一个大点的话题——清浮动    来看下例: <!DOCTYPE html> <html> <head> <meta charset="U ...

  10. DP+矩阵快速幂 HDOJ 5318 The Goddess Of The Moon

    题目传送门 /* DP::dp[i][k] 表示选择i个字符串,最后一次是k类型的字符串,它由sum (dp[i-1][j]) (a[j], a[k] is ok)累加而来 矩阵快速幂:将n个字符串看 ...