您的位置:首页 > 移动开发 > Android开发

Ubuntu下调试Android源码

2015-09-18 14:43 513 查看
一、生成IMG文件

定位到Android源目录下

     cd /AndroidSource/Android44/

顺序执行下列命令

   . build/envsetup.sh

  lunch

  make -j4

二、启动虚拟机

首先你需要设置一下emulator工具的目录之类的,这个不细说了,

要在.bashrc中新增环境变量,如下

ANDROID_PRODUCT_OUT=~/android/out/target/product/generic

ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/bin

这里是设置你的输出文件的位置和bin工具目录,不用多解释吧?

然后在命令行输入:

export PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};

上面是导入了相关的配置,然后使之生效。

source ~/.bashrc

接着切换到输出的system文件夹

cd ~/android/out/target/product/generic

然后来创建模拟器

emulator -system system.img -data userdata.img -ramdisk ramdisk.img

如果你运气够好的话,也许现在已经在运行了,不过我运气明显不够好。

提示一:

emulator: ERROR: You did not specify a virtual device name, and the system

directory could not be found.

If you are an Android SDK user, please use ‘@<name>’ or ‘-avd <name>’

to start a given virtual device (see -help-avd for details).

Otherwise, follow the instructions in -help-disk-images to start the emulator

 

既然人家提示了,那就按照步骤走吧,输入命令:

emulator -help-avd

接着提示如下:

use ‘-avd <name>’ to start the emulator program with a given Android

Virtual Device (a.k.a. AVD), where <name> must correspond to the name

of one of the existing AVDs available on your host machine.

See -help-virtual-device to learn how to create/list/manage AVDs.

As a special convenience, using ‘@<name>’ is equivalent to using

‘-avd <name>’.

跟着提示继续走,输入命令:

emulator -help-virtual-device

又是提示了:

An Android Virtual Device (AVD) models a single virtual

device running the Android platform that has, at least, its own

kernel, system image and data partition.

Only one emulator process can run a given AVD at a time, but

you can create several AVDs and run them concurrently.

You can invoke a given AVD at startup using either ‘-avd <name>’

or ‘@<name>’, both forms being equivalent. For example, to launch

the AVD named ‘foo’, type:

emulator @foo

The ‘android’ helper tool can be used to manage virtual devices.

For example:

android create avd -n <name> -t 1 # creates a new virtual device.

android list avd # list all virtual devices available.

Try ‘android –help’ for more commands.

Each AVD really corresponds to a content directory which stores

persistent and writable disk images as well as configuration files.

Each AVD must be created against an existing SDK platform or add-on.

For more information on this topic, see -help-sdk-images.

SPECIAL NOTE: in the case where you are *not* using the emulator

with the Android SDK, but with the Android build system, you will

need to define the ANDROID_PRODUCT_OUT variable in your environment.

See -help-build-images for the details.

说实在的,这提示看着很郁闷,让你跳来跳去,就是不能解决问题。

直接创建avd吧,先看下说明:

Usage:

android [global options] create avd [action options]

Global options:

-h –help : Help on a specific command.

-v –verbose : Verbose mode, shows errors, warnings and all messages.

-s –silent : Silent mode, shows errors only.

Action “create avd”:

Creates a new Android Virtual Device.

Options:

-c –sdcard : Path to a shared SD card image, or size of a new sdcard for

the new AVD.

-n –name : Name of the new AVD. [required]

-a –snapshot: Place a snapshots file in the AVD, to enable persistence.

-p –path : Directory where the new AVD will be created.

-f –force : Forces creation (overwrites an existing AVD)

-s –skin : Skin for the new AVD.

-t –target : Target ID of the new AVD. [required]

-b –abi : The ABI to use for the AVD. The default is to auto-select the

ABI if the platform has only one ABI for its system images.

看明白了吧?

 android create avd -n test2 -f -p /home/thonatos/test -t 1

然后会有提示:

Auto-selecting single ABI armeabi-v7a

Android 4.0.3 is a basic Android platform.

Do you wish to create a custom hardware profile [no]no

Created AVD ‘test2′ based on Android 4.0.3, ARM (armeabi-v7a) processor,

with the following hardware config:

hw.lcd.density=240

vm.heapSize=48

hw.ramSize=512

创建好了,不过你的模拟器估计一运行就出错吧。(我故意滴。。。别怪我。。)

切换到刚才创建模拟器的目录,然后看看有什么东东,打开config.ini

hw.lcd.density=240

skin.name=WVGA800

skin.path=platforms/android-15/skins/WVGA800

hw.cpu.arch=arm

abi.type=armeabi-v7a

hw.cpu.model=cortex-a8

vm.heapSize=48

hw.ramSize=512

image.sysdir.1=system-images/android-15/armeabi-v7a/

知道该做什么了吧?改吧,把相关的目录改成你自己的,然后再执行一下

emulator @test2

怎么样!是不是已经运行啦?呵呵,恭喜哈!
二、更改修改后的APK1.下载Android源代码的过程就不说了,网上资料一大把 
2.安装jdk1.5的步骤就不说了,网上资料一大把 
3.下载源代码我放置的目录是/home/wuyutaott/android 
4.进入android命令行中输入make进行编译,漫长的等待,需要半天时间 
5.配置环境 
  gedit .bashrc  注意路径,我是在home/wuyutaott/下进行的 

  将一下2行添加到文件末尾: 

  export PATH=$PATH:/home/xxx/android/out/host/linux-x86/bin 

  export ANDROID_PRODUCT_OUT=/home/xxx/android/out/target/product/generic 
6.启动模拟器,一直都不用管,要不然重新启动很浪费时间 
  emulator 
7.选择一个项目进行修改,这里我选择的是Launcher,修改其源代码 
8.进行模块编译 
  mmm packages/apps/Launcher  注意路径,我是在home/wuyutaott/android下进行的 
  如果提示没有找到mmm命令 
  执行. build/envsetup.sh  source build/envsetup.sh (应 用 修改 ) 
8.编译过之后 
  /home/wuyutaott/android/out/target/product/generic/system/app/Launcher.apk这个文件会更新 
  查看其属性会看到他的更新时间就是你刚才模块编译的时间 
9.下一步需要把更新之后的Launcher.apk安装到模拟器上 
  adb install -r /home/wuyutaott/android/out/target/product/generic/system/app/Launcher.apk 
  模拟器会暗屏一下,然后再亮起来,说明它自己重新启动了,但是速度很快 
  OK可以看到修改之后的效果了 
10.我以前的做法是模块编译之后,$make snod重新生成system.img(非常浪费时间)。然后把模拟器关掉重新启动(非常浪费时间),现在改进了之后速度快了不少。 
11.下一步重点的就是想办法在ubuntu上吧eclipse配置好,好进行调试,和编译代码,要不然在.java文件中直接改代码也是一件痛苦的事情,但是ubuntu下配置eclipse进行Android源代码开发我还不会,比较麻烦,有兴趣的朋友

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: