`
meohao
  • 浏览: 99306 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

关于Android开发环境的构建方法总结

阅读更多
转自:http://blog.csdn.net/ecaol/archive/2010/03/24/5410915.aspx

本方法适用于Android SDK 2.1环境下的程序开发

安装JDK
•    在java.sun.com下载JDK并安装
•    在“系统属性”的“高级”选项卡中点击“环境变量”,然后添加如下系统环境变量:

1.    在PATH环境变量后追加 JDK安装路径中的bin路径,本机为
C:\Program Files\Java\jdk1.6.0_18\bin
2.    新建CLASSPATH环境变量或在CLASSPATH环境变量后追加JDK安装路径中的lib路径和demo路径,本机为
C:\Program Files\Java\jdk1.6.0_18\demo;C:\Program Files\Java\jdk1.6.0_18\lib

安装Eclipse
•    在eclipse.org下载Eclipse IDE for Java Developers的Windows 32bit版本
•    下载完成后解压即可使用


安装Android SDK OR 离线安装

•    在Android Developers下载android-sdk_r05-windows.zip,下载完成后解压到任意路径
•    运行SDK Setup.exe,点击Available Packages,如果没有出现可安装的包请点击Settings,选中Misc中的"Force https://..."这项,再点击Available Packages
•    选择希望安装的SDK及其文档或者其它包,点击Installation Selected、Accept All、Install Accepted,开始下载安装所选包
•    添加SDK安装目录中的tools文件夹路径至系统PATH环境变量,本机为
C:\Android\android-sdk-windows\tools

关于离线安装

用上面方法更新的时候速度很慢。
更要等很久。所以我们可以直接把那些包下载下来安装。
地址就是
https://dl-ssl.google.com/androi ... 2.0_r01-windows.zip
https://dl-ssl.google.com/androi ... 2.1_r01-windows.zip
https://dl-ssl.google.com/androi ... -1.1_r1-windows.zip
https://dl-ssl.google.com/androi ... 1.5_r03-windows.zip
https://dl-ssl.google.com/androi ... 1.6_r02-windows.zip
https://dl-ssl.google.com/androi ... ver_r03-windows.zip
https://dl-ssl.google.com/androi ... ogle_apis-6_r01.zip
https://dl-ssl.google.com/androi ... ogle_apis-5_r01.zip
https://dl-ssl.google.com/androi ... ogle_apis-4_r02.zip
https://dl-ssl.google.com/androi ... ogle_apis-7_r01.zip




下完之后,
名字以android的,解压到platforms里面
以google_apis开头的,解压到addons里面
usb驱动的,直接解压到根目录


安装Eclipse插件 ADT
•    Start Eclipse, then select Help > Install New Software.
•    In the Available Software dialog, click Add...
•    In the Add Site dialog that appears, enter a name for the remote site (for example, "Android Plugin") in the "Name" field.
In the "Location" field, enter this URL:
https://dl-ssl.google.com/android/eclipse/
如果无法通过上面的地址获得插件,可将https替换为http。(https is preferred for security reasons)
•    Back in the Available Software view, you should now see "Developer Tools" added to the list.
•    Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next.
•    In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed.
•    Click Next to read and accept the license agreement and install any dependencies, then click Finish.
•    Restart Eclipse.

配置ADT

在Eclipse中:
•    选择Window > Preferences...
•    在左边的面板选择Android,然后在右侧点击Browse...并选中SDK路径,本机为:
C:\Android\android-sdk-windows
•    点击Apply、OK。配置完成。

创建AVD

为使Android应用程序可以在模拟器上运行,必须创建AVD
•    在Eclipse中。选择Windows > Android SDK and AVD Manager
•    点击左侧面板的Virtual Devices,在右侧点击New
•    填入Name,选择Target的API,SD Card大小任意,Skin随便选,Hardware目前保持默认值
•    点击Create AVD即可完成创建AVD

Create a New Android Project
After you've created an AVD, the next step is to start a new Android project in Eclipse.
1.    From Eclipse, select File > New > Project.
If the ADT Plugin for Eclipse has been successfully installed, the resulting dialog should have a folder labeled "Android" which should contain "Android Project". (After you create one or more Android projects, an entry for "Android XML File" will also be available.)
2.    Select "Android Project" and click Next.

3.    Fill in the project details with the following values:
o    Project name: HelloAndroid
o    Application name: Hello, Android
o    Package name: com.example.helloandroid (or your own private namespace)
o    Create Activity: HelloAndroid
o    Min SDK Version: 7
Click Finish.

Here is a description of each field:

Project Name
This is the Eclipse Project name — the name of the directory that will contain the project files.
Application Name
This is the human-readable title for your application — the name that will appear on the Android device.
Package Name
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.
Your package name must be unique across all packages installed on the Android system; for this reason, it's very important to use a standard domain-style package for your applications. The example above uses the "com.example" namespace, which is a namespace reserved for example documentation — when you develop your own applications, you should use a namespace that's appropriate to your organization or entity.

Create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.
Min SDK Version(这个是设置程序希望运行在的系统版本)
==================================
Tips: 这里的Min SDK Version会根据我们选择的Build Target改变,
表示程序将运行在哪个系统版本之上,对应的数值关系如下:
Android 1.5:Level API 3
Android 1.6:Level API 4
Android 2.01:Level API 6
Android 2.1:Level API 7
我们这里选择Android 2.1,故Min SDK Version为7
==================================
This value specifies the minimum API Level required by your application. If the API Level entered here matches the API Level provided by one of the available targets, then that Build Target will be automatically selected (in this case, entering "2" as the API Level will select the Android 1.1 target). With each new version of the Android system image and Android SDK, there have likely been additions or changes made to the APIs. When this occurs, a new API Level is assigned to the system image to regulate which applications are allowed to be run. If an application requires an API Level that is higher than the level supported by the device, then the application will not be installed.
Other fields: The checkbox for "Use default location" allows you to change the location on disk where the project's files will be generated and stored. "Build Target" is the platform target that your application will be compiled against (this should be selected automatically, based on your Min SDK Version).
Notice that the "Build Target" you've selected uses the Android 1.1 platform. This means that your application will be compiled against the Android 1.1 platform library. If you recall, the AVD created above runs on the Android 1.5 platform. These don't have to match; Android applications are forward-compatible, so an application built against the 1.1 platform library will run normally on the 1.5 platform. The reverse is not true.
Your Android project is now ready. It should be visible in the Package Explorer on the left. Open the HelloAndroid.java file, located inside HelloAndroid > src > com.example.helloandroid).
It should look like this:

下面是点完Finish按钮之后自动生成的代码:

view plaincopy to clipboardprint?
package com.example.helloandroid;  
  
import android.app.Activity;  
import android.os.Bundle;  
  
public class HelloAndroid extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
    }  
}  
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Notice that the class is based on the Activity class. An Activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. The onCreate() method will be called by the Android system when your Activity starts — it is where you should perform all initialization and UI setup. An activity is not required to have a user interface, but usually will.
Now let's modify some code!

构建 UI
Take a look at the revised code below and then make the same changes to your HelloAndroid class. The bold items are lines that have been added.

下面让我们修改一下代码:
view plaincopy to clipboardprint?
package com.android.helloandroid;  
  
import android.app.Activity;  
import android.os.Bundle;  
import android.widget.TextView;  
  
public class HelloAndroid extends Activity {  
   /** Called when the activity is first created. */  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
       super.onCreate(savedInstanceState);  
       TextView tv = new TextView(this);  
       tv.setText("Hello, Android");  
       setContentView(tv);  
   }  
}  
package com.android.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } }
执行代码:Hello,Android

Eclipse的插件使得你的程序很容易运行。选择Run>Open Run Dialog菜单。(Eclipse3.4版本中,菜单为Run->Run Configurations)可以看到这样的对话框

下一步,选择“Android Application”,点击在左上角(按钮像一张纸上有个“+”号)或者双击“Android Application”。 有个新的选项“New_configuration”。

将 名字改得更形象一点,如“Hello,Android”,然后按Browse按钮选择你的项目,(如果你Eclipse里有多个Android项 目需要打开,确定要选择正确)插件会会自动扫描你项目里的活动子类,然后在“活动”的下拉菜单里加载。如果你的“Hello,Android”项目只有一 个,它将被设置为默认项目,然后你可以继续。
点击“Apply”按钮,这里有个例子:

这样就可以了,点击“Run”按钮,Android的模拟器启动。一启动你的程序就会出现,当一切OK,你可以看到:

这样就可以了,点击“Run”按钮,Android的模拟器启动。
启动完毕后你的程序就会出现,
如果不出现,有时候是因为有键盘锁的原因,
用鼠标将键盘锁解开就一切OK,你可以看到:Hello Android.

使用XML构建UI
你 刚刚完成的“Hello, World”的例子使用的是我们称为“可编程”的UI层,意思是你通过编写代码来组建UI层。当你开发了足够多的UI程序,你会发现一些很糟糕的现象: 一些小的变化需要你做大量的代码改动。你常常会忘记将View连接起来,这样会导致一些错误,浪费你很多时间去调试代码。
这就是Android为什么提供一个可变化的UI开发模块:基于XML的文件。最简单解释这个概念就是演示个例子。这里有个XML的文件,它能达到和你刚才完成代码同样的效果:
view plaincopy to clipboardprint?
<?xml version="1。0" encoding="utf-8"?>  
<TextView xmlns:android="http://schemas.android.com/apk/res/android"  
  android:layout_width="fill_parent"  
  android:layout_height="fill_parent"  
  android:text="Hello, Android"/>  
<?xml version="1。0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Hello, Android"/>
通 常Android里XML文件结构是很简单的。只是一些标记的树形集合,每个标记就是一个视图类。在这个例子中,它就是一个简单的 TextView元素的树,你可以在XML文件里使用任何扩展类的名字作为你的标记,这也包括你在你的自己的代码里定义的名字。这个结构使得你能使用简单 结构和语法快速的组建UI,这种模型就像网站的开发模型,你能够将UI和程序逻辑分开,单独获取或者填充数据。
在这个例子里,有4个XML属性,下面是属性的大概意思:


xmlns:android     这是一个XML命名空间,告诉Android开发工具你准备使用Android命名空间里的一些通用属性。在所有Android XML设计文件中最外层的标记必须使用这个属性。

android:layout_width     这个属性定义了这个视图需要占用的屏幕宽度。在这个例子中,我们仅有的一个视图可以占用整个屏幕,那就是“fill_parent”的意思。

android:layout_height     这个和“layout_width”差不多,表示占用屏幕的高度。

android:text     这个设置文本显示内容,在这个例子里,我们使用“Hello,Android”。

这就是XML的布局,你需要把这个文件放在什么位置? 放在你的工程/res/layout下就可以。“res”是“resource”的简称,这个目录包含了所有应用程序需要的非代码部分。比如图片、字符串、XML文件。

Eclipse插件为你创建了这些XML文件中的一个。在我们上面的范例,我们根本没有使用过它。在包的管理器里,展开目录/res/layout,编辑main.xml文件,替换上面的文本然后保存修改。
在从代码目录里打开 HelloAndroid/gen/com.example.helloandroid/R.java文件,你可以看到他们像这样:
view plaincopy to clipboardprint?
public final class R {  
    public static final class attr {  
    };  
    public static final class drawable {  
        public static final int icon=0x7f020000;  
    };  
    public static final class layout {  
        public static final int main=0x7f030000;  
    };  
    public static final class string {  
        public static final int app_name=0x7f040000;  
    };  
};  
public final class R { public static final class attr { }; public static final class drawable { public static final int icon=0x7f020000; }; public static final class layout { public static final int main=0x7f030000; }; public static final class string { public static final int app_name=0x7f040000; }; };
R.java是文件中所有资源的索引界定值定义。你在代码中使用这个类,就像在你的项目里使用一个简洁的方法表示你的资源。在Eclipse这样的IDE工具里,这个方式对于代码自动完成功能还是非常有效的,因为这能让你快速得定位你要寻找的东西。
有个重要点需要注意的是有个内部类“main”,是“layout”的成员类。Eclipse插件提醒你加了一个新的XML文件,然后生成R.java文件,当你加入其他资源到你的工程里,你可以看到R.java在同步更改。
分享到:
评论

相关推荐

    Android 开发环境下载

    总结,Android开发环境的搭建涉及多个组件,包括Android Studio、SDK、JDK、AVD等。理解这些工具的功能并掌握其配置方法,是成为一名合格的Android开发者的基础。同时,持续学习和跟进行业动态,将有助于提升开发...

    搭建Android开发环境

    搭建Android开发环境是每个想要踏入Android应用开发领域的初学者必经的第一步。这一过程涉及到多个环节,包括安装必要的软件、配置开发工具以及设置环境变量。本文将详细讲解这些步骤,帮助初学者顺利构建起Android...

    史上最全Android开发环境搭建-Android

    本文将详细介绍如何一步步搭建史上最全的Android开发环境。 1. **Java Development Kit (JDK)**: Android应用是基于Java语言开发的,因此首要任务就是安装JDK。确保下载并安装适用于您操作系统的最新版本的JDK。...

    win7_64位Android开发环境搭建

    总结一下,搭建Android开发环境包括以下步骤: 1. 访问Android官网并下载SDK。 2. 解压SDK并运行SDK Manager。 3. 在SDK Manager中安装所需组件。 4. 下载并安装ADT插件到Eclipse。 5. 重启Eclipse完成安装。 确保...

    Windows7部署Android开发环境傻瓜式教程

    ### Windows7上构建Android开发环境详尽指南 在Windows7操作系统上搭建Android开发环境,是一项对初学者来说可能显得较为复杂但实则有序的过程。本文将深入解析如何在Windows7环境下,通过Eclipse和ADT插件来部署...

    学习android(一)搭建android开发环境相关说明

    这篇博文将引导你了解如何系统地构建Android开发环境,包括所需的工具、步骤以及一些常见的问题解决方法。以下是对这个主题的详细说明: 首先,你需要安装Java Development Kit (JDK)。因为Android应用是用Java语言...

    搭建Android开发环境和构建第一个Android程序(Android studio版)

    搭建Android开发环境是每个Android开发者入门的必经之路,而Android Studio作为官方推荐的集成开发环境,其功能强大且易用。本教程将详细介绍如何在Windows操作系统上使用Android Studio搭建开发环境并创建第一个...

    Android入门到精通-实训任务1-搭建Android开发环境

    通过本次实训,学员不仅学会了搭建Android开发环境的基础技能,还掌握了如何构建自己的Android开发项目、理解Android项目的架构,并能够熟练地在模拟器中安装、运行和卸载apk程序。这些技能对于进一步学习Android...

    使用IntelliJ IDEA 13搭建Android集成开发环境(图文教程)

    首先,搭建Android开发环境需要准备以下软件和工具: 1. JavaSDK(Software Development Kit):这是开发Android应用不可或缺的组件。你需要从Oracle官网下载适用于你的操作系统的JavaSDK版本,并进行安装。安装...

    实验1-Android开发环境与第一个Android程序.doc

    实验1-Android开发环境与第一个Android程序是针对嵌入式应用开发课程的一项实践任务,旨在让学生熟悉Android开发的基础流程和工具。在这个实验中,学生需要完成以下关键知识点的学习和操作: 1. **Android开发环境...

    QT Android 开发环境搭建(全)

    在本文中,我们将详细探讨如何搭建完整的Qt Android开发环境,包括所有必要的组件和步骤。首先,确保你已准备好以下软件包: 1. `qt-opensource-windows-x86-5.9.0` - 这是Qt 5.9版本的安装文件,用于创建Qt应用...

    C#环境下开发Android软件环境搭建

    在C#环境下开发Android软件,主要是利用Microsoft的Visual Studio(VS)和开源的Mono框架,使得C#开发者能够利用熟悉的...通过遵循上述指南,开发者可以逐步构建一个完整的开发环境,从而开始C#开发Android应用的旅程。

    Linux系统下的Android开发环境搭建[定义].pdf

    总之,Linux系统下的Android开发环境搭建涉及到多个层次的技术,从安装基础开发工具到深入系统层面的定制,都需要开发者具备一定的编程和系统知识。随着Android版本的不断更新,开发者需要持续学习和适应新的API及...

    Android开发从零开始——Android开发环境搭建

    【Android开发从零开始——Android开发环境搭建】 在进入Android应用程序开发的世界之前,首要任务是构建一个有效的开发环境。本文将详细介绍如何在Windows操作系统上搭建Android开发环境,确保每个步骤都清晰明了...

    五步搞定Android开发环境部署

    【Android开发环境部署详解】 Android应用开发环境的搭建是初学者必须经历的第一步,下面将详细解析这五步过程。 第一步:安装JDK JDK(Java Development Kit)是Java编程语言的软件开发工具包,它包含Java运行...

    Android视频教程 第二讲建立Android开发环境

    本教程——"Android视频教程 第二讲:建立Android开发环境"将引导你系统地完成这一过程。Android开发环境主要由几个核心组件构成,包括Java Development Kit (JDK)、Android Studio、Android SDK以及模拟器或真机...

    android开发环境 下载地址

    Android开发环境主要由以下几个核心组件构成:Android Studio、Java Development Kit (JDK)、Android SDK(Software Development Kit)以及一些必要的开发工具。以下是对这些组件的详细介绍: 1. **Android Studio*...

    android开发环境配置

    在构建Android开发环境时,尤其是针对使用Unity进行游戏或应用开发的场景,一系列的软件配置与集成变得至关重要。本文将详细解析如何搭建一个基于Unity、Eclipse、Android SDK等工具的开发环境,以及如何实现Java...

Global site tag (gtag.js) - Google Analytics