怎样使用Eclipse来开发Android源码

本文介绍了如何使用 Eclipse 构建和调试 Android 应用程序,包括安装和更新 SDK、配置 Eclipse 缓存、导入工程配置文件及源码等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

eclipse 用在 android 上的功能

1、用 eclipse来编辑代码、检查错误

   2、不在 eclipse上编译、运行 android源码程序,只能在命令行通过 make( mm mmm)编译 android源码

   3、可以在 eclipse上调试 android源码程序(原理: eclipse通过 ddms服务器 emulator上进行调试),并可以单步调试、断点调试。

 

二、建立基本的 android 开发环境

最标准的请参考官方文档,我在这里进行简单介绍,主用针对 linux系统和 Eclipse 3.4

( ).Installing the SDK

  1. Start Eclipse, then select Help > Software Updates... .

  2. In the dialog that appears, click the Available Software tab.

  3. Click Add Site...

  4. Enter the Location:

https://dl-ssl.google.com/android/eclipse/

If you have trouble aqcuiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).

Click OK .

  1. Back in the Available Software view, you should see the plugin listed by the URL, with "Developer Tools" nested within it. Select the checkbox next to Developer Tools and click Install...

  2. On the subsequent Install window, "Android DDMS" and "Android Development Tools" should both be checked. Click Next .

  3. Read and accept the license agreement, then click Finish .

  4. Restart Eclipse.

If you encounter this error when installing the ADT Plugin for Eclipse:

	An error occurred during provisioning.
Cannot connect to keystore.
JKS

...then your development machine lacks a suitable Java VM. Installing Sun Java 6 will resolve this issue and you can then reinstall the ADT Plugin.

(二) .Upgrading the SDK

	1.Select Help


> Software Updates

.

2.Select the Available Software tab.

3.Expand the entry for the Andriod plugin (may be listed as the location URL) and select "Developer Tools" by checking the box next to it, then click Install .

4.On the next window, "Android DDMS" and "Android Development Tools" should both be checked. Click Finish .

5.Restart Eclipse.

 

三、修改 eclipse 程序的配置

1、修改 eclipse缓存设置

  把 eclipse.ini(在 eclipse软件 的安装目录下)的 3个值改为下面的值:

   -Xms128m

   -Xmx512m

   -XX:MaxPermSize=256m

   2、把 Android工程中的 android-formatting.xml android.importorder导入 eclipse

   android-formatting.xml用来配置 eclipse编辑器的代码风格; android.importorder用来配置 eclipse import的顺序和结构。

  在 window->preferences->java->Codestyle->Formatter中导入 android-formatting.xml

  在 window->preferences->java->Codestyle->OrganizeImports中导入 android.importorder

(android-formatting.xml android.importorder development/ide/eclipse/)

 

四、把 Android 工程中的 eclipse 工程配置文件复制到 android 源码根目录下

   cp development/ide/eclipse/.classpath ./

   chmod u+w .classpath # Make the copy writable

五、编译 android 源码

android源码根目录下通过make进行编译,请注意一些配置,具体可参考<android源码的编译>
我在这进行简单介绍

cd android源码目录

   . build/envsetup.sh

make -j4(编译整个工程)

  

六、把 android 源码作为一个工程导入 eclipse

  导入前先检查 .classpath里的文件在 android源码中是否有相应的文件(文件夹),否则也会破坏 android源码(一般是多添加文件 /文件夹), .classpath里多余的路径可删除

  新建 JavaProject(不是 androidproject,否则会破坏 android源码),选择从已存在的工程导入,工程名任意,完成。

  导入时, eclipse build工程,比较慢。导完后,一般都没有错误。

七、 eclipse 上调试 android 里的程序。

先执行:

   cd android源码目录

   . build/envsetup.sh

   lunch 1 # to build the emulator

   emulator & # you should see a GUI picture of a phone

   ddms & # you should get a splufty debugging console

  然后在 eclipse中配置调试类型和端口:

   在 Run->Debug Configurations->Remotejavaapplication上双击,然后,” Host:”设为 localhost,” Port:”设为 8700,” ConnectionType” Standard(SocketAttach)

  然后“ Apply”

  注意,在点击” Debug”时苦出错,说 8700端口被占用,那么把 DDMS程序关掉,重新打开 DDMS OK了。如果提供连不到 VM错误时,请注意,要先在 DDMS中选中某一进程(对应某一应用程序),才能在 eclipse执行 Debug

  在 eclipse调试时,可以设断点、单步调试。

  

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值