1. android dalvik debugging


디버깅은 개발에 있어서 정말 중요하다.

달빅을 개발할 때 버추얼 머신 디버깅을 하면서 개발 효율이 많이 올라갔었다.

그당시 참고 사이트.

http://androidkr.blogspot.kr/2010/10/android-gdb-dalvik-vm.html


2. android art debugging


dalvik은 버추얼 머신위에서 어플리케이션이 돌아가기때문에 달빅을 디버깅을 하면 된다. 어플리케이션을 돌리는 프로그램이 app_process 이므로 이것을 시작으로 디버깅을 시작했다.

현재 내가 하는 것은 art에서 돌아가는 시스템 프로그램들이다.



3. 준비물 확인


  • gdbserver - 안드로이드 디바이스에서 프로그램과 엮겨 호스트의 gdb의 입력을 받아들인다.
  • gdb - 호스트에서 gdbserver와 통신하며 프로그램을 디버깅 한다.

4. 호스트 준비하기

호스트는 우리의 컴퓨터이다. 컴퓨터를 준비하고 소스코드를 다운받고 빌드한다.


5. 머신 준비하기

나의 머신은 nexus 7. 4.에서 준비한 빌드 이미지를 머신에 플래시 한다.
이 과정은 다른 곳에도 많으니 생략하자.


6. 호스트와 머신간 통신

호스트를 통해 머신의 프로그램을 디버깅 할 것이기 때문에, 당연히 호스트와 머신은 통신을 할 수 있어야 한다.
이 통신을 하기 위해 로컬 네트워크를 이용한다. 로컬 허브에 머신을 와이파이로 연결하고, 머신으로 포트를 포워딩 한다.




7. 머신에서 해야할 일


안드로이드 쉘에 접속한다.

$adb shell

디버깅 하고자 하는 프로그램을 실행한다. 여기서 프로그램은 안드로이드 어플리케이션이 아닌 art의 프로그램이다.

이 프로그램의 PID를 확인한다.

#ps

이 프로그램을 gdbserver에 등록한다.

#gdbserver 163.152.73.73:2345 --attach 3403

위에서 IP주소는 내 서버 호스트의 IP 주소이고 port는 6.에서 설정한 port이다. --attach 뒤의 숫자는 디버깅할 프로그램의 PID.


다음과 같이 메세지가 나온다.

gdbserver 163.152.73.73:2345 --attach 3332

Attached; pid = 3332

Listening on port 2345

Remote debugging from host 163.152.73.73


이제 호스트에서 디버깅을 하면 된다.



8. 호스트에서 해야할 일


머신과 통신할 gdb가 있어야 한다.

나의 경우는 arm 머신이기 때문에 다음의 gdb를 이용한다.

prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-gdb


이때 7에서 실행하는 프로그램을 명시해 주어야 한다. art에서 사용하는 프로그램 대부분은 다음 path에 있다.

out/target/product/flo/system/bin


adb를 디버깅한다고 가정하면.....

$android-5.0.1_r1/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-gdb out/target/product/flo/symbols/system/bin/adb

와 같다.


그렇게 되면 gdb 가 실행이 된다.

그리고 나서 이 프로그램의 symbol들을 알 수 있는 path를 지정해 준다.

$set solib-search-path out/target/product/flo/symbols/system/lib


이제 gdbserver에 접속하도록 하자.

(gdb) target remote 163.152.73.82:2345

위에서 IP주소는 나의 허브 아이피 주소이고, 포트는 머신으로 포워딩된 포트이다.


Remote debugging using 163.152.73.82:2345

위와 같이 메세지가 나오면서 연결이 된다.






기타 사항


맨처음에 가장 고생했던 것.

머신에서 gdbserver를 실행하려고 하면 계속 다음과 같은 메세지를 뱉었다.

Cannot attach to lwp 3403: Operation not permitted (1)

Exiting

그 이유는 내가 디버깅 하고자 한 프로그램이 root권한을 필요로 했던것.


이를 해결 하기 위해 adb를 root 권한으로 실행한다.

$adb root

$adb shell


이후에 안드로이드 쉘 프롬프트가 root로 변한 것을 볼 수 있고, 위와 같은 에러도 발생하지 않았다.








http://source.android.com/source/downloading.html

안드로이드 빌드를 위한 사전 작업을 마쳤다면 이제 안드로이드 소스코드를 받을 차례이다.
위의 링크에서 설명한대로 차례 차례 진행해 보도록 하자.


1. repo 설치


소스코드는 어디 홈페이지에서 받는 것이 아니라 repo라는 것의 도움받는다.

다음을 입력해 repo를 위한 폴더를 만들로 폴더를 PATH에 등록한다.

$ mkdir ~/bin

$ PATH=~/bin:$PATH


repo를 받고 실생 가능한 파일로 만들어 준다.

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

$ chmod a+x ~/bin/repo


2. 안드로이드 소스코드 다운로드.


안드로이드를 위한 폴더를 만들어 주자.

$ mkdir Android_project

$ cd Android_project


repo를 이용해 source code를 받자.

$ repo init -u https://android.googlesource.com/platform/manifest


위와 같이 적용하니 다음과 같은 메세지가 나온다.

error.GitError: manifests var: 

*** Please tell me who you are.


Run


  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"


to set your account's default identity.

Omit --global to set the identity only in this repository.


fatal: unable to auto-detect email address (got 'nold@nold-VB.(none)')


나의 email 주소를 모르겠단다.
저기 나와 있는 대로 명령어를 실행하고 다시한번 repo init을 하자.
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
$ repo init -u https://android.googlesource.com/platform/manifest

https://android.googlesource.com/platform/manifest

여기에 들어가면 여러 버젼이 나온다. 나는 4.4.2_r2를 사용하기로 했으니 다음과 같이 입력한다.

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r2


이제 정말 소스를 받도록 하자.

$ repo sync


이것은 시간이 많이 걸린다. 가서 밥이나 먹고 오자



3. 디바이스를 위한 드라이버 다운로드


nexus5에 안드로이드를 올리기 위해서는 디바이스 드라이버도 필요하다.

http://source.android.com/source/building-devices.html

위 페이지 중간부분에 

Picking and building the configuration that matches a device

밑에 드라이버 다운로드를 위한 링크가 있다.

https://developers.google.com/android/nexus/drivers

여기에 들어가서 Binaries for Nexus 5 (GSM/LTE) ("hammerhead") 밑의 Android 4.4.2 (KOT49H)를 눌러보자.



위와 같이 장치 드라이버가 나온다. 

드라이버를 다운로드 받기 위한 폴더를 만들자.

$ mkdir ~/android_driver

$ cd ~/android_driver


드라이버를 wget을 이용해서 다운 받는다. 

각각의 Link에 대해 다음을 수행한다.

$ wget "Link 우클릭 -> 링크주소복사"


다음과 같은 세 개의 파일이 받아졌다.

broadcom-hammerhead-kot49h-a670ed75.tgz

qcom-hammerhead-kot49h-518133bf.tgz

lge-hammerhead-kot49h-e6165a67.tgz


이 파일들의 압축을 해제 하자.

$ tar zxvf broadcom-hammerhead-kot49h-a670ed75.tgz

$ tar zxvf qcom-hammerhead-kot49h-518133bf.tgz

$ tar zxvf lge-hammerhead-kot49h-e6165a67.tgz


다음과 같이 세개의 파일이 생겼다.

extract-qcom-hammerhead.sh

extract-broadcom-hammerhead.sh

extract-lge-hammerhead.sh



4. 장치 드라이버 설치


안드로이드 소스코드가 있는 곳으로 이동한다.

$ cd ~/android_4.4.2_r2


이 폴더에서 아까 받은 파일들을 실행한다.

$ ~/android_driver/extract-broadcom-hammerhead.sh


The license for this software will now be displayed.

You must agree to this license before using this software.


Press Enter to view the license


엔터를 입력하자.

   1.  Special Definitions


      a.  The term "Android" means the open source mobile platform, software

          stack, operating system, middleware, application programming

          interfaces and mobile applications under the trade-name "Android"

          distributed at Android.com.


      b.  The term "Android Applications" means a software application or

          open-source contribution developed by You, designed to operate with

          Android that does not contain or incorporate any of the Software.

--More--

위와 같이 나오는데 스페이스 바를 눌러 끝까지 진행한다.
      e.  Entire Agreement. This Agreement completely and exclusively states
          the agreement between You and Licensor regarding this subject
          matter.

Type "I ACCEPT" if you agree to the terms of the license:

커서가 깜빡 거리는 데, I ACCEPT를 입력하면 된다.
세 개의 파일 모두 같은 방식으로 진행한다.


5. 안드로이드의 타겟 설정

안드로이드 소스코드 폴더로 이동한다.
$ cd ~/android_4.4.2_r2

다음을 입력해 빌드를 위한 세팅을 한다.
$ . build/envsetup.sh

그리고 타겟을 설정하기 위해 다음을 입력한다.
$ lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_x86-eng
     3. aosp_mips-eng
     4. vbox_x86-eng
     5. mini_mips-userdebug
     6. mini_armv7a_neon-userdebug
     7. mini_x86-userdebug
     8. aosp_mako-userdebug
     9. aosp_hammerhead-userdebug
     10. aosp_grouper-userdebug
     11. aosp_tilapia-userdebug
     12. aosp_deb-userdebug
     13. aosp_flo-userdebug
     14. aosp_manta-userdebug

Which would you like? [aosp_arm-eng] 

여기서 적당한 것을 입력하면 된다.
xxx_yyy-zzz 다음과 같은 형식인데, xxx는 소스코드의 형식이고, yyy는 안드로이드가 올라가는 타겟 디바이스이다. zzz는 안드로이드의 빌드 형식을 나타낸다.

nexus5는 hammerhead이고 개발자 입장에서 빌드를 할것이기 때문에 zzz는 eng를 선택한다.
 aosp_hammerhead-eng

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.2
TARGET_PRODUCT=aosp_hammerhead
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=krait
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=KVT49L
OUT_DIR=out
============================================

결과를 보면 많은 정보를 알 수 있다.

그리고 대망의 빌드를 하자. 이 또한 시간이 많이 걸린다.

$ make -j 2
뒤의 숫자는 자신의 코어 수 만큼만 주면 된다.

Checking build tools versions...
************************************************************
You are attempting to build with an unsupported JDK.
 
You use OpenJDK but only Sun/Oracle JDK is supported.
Please follow the machine setup instructions at
************************************************************
build/core/main.mk:152: *** stop.  Stop.
위와 같은 메세지를 뱉어 내고 죽어버렸다.
링크된 페이지에 가면 open JDK를 사용 하라고 나와 있는데.... sun/oracle의 JDK를 사용하라고 한다.

위 링크에서 sun/oracle jdk를 설치하는 방법을 설명해 놓았다.
설치 후 다시 한번 빌드 해보자.

$ make -j 2


'Android' 카테고리의 다른 글

android art 디버깅 하기 (dex2oat)  (0) 2015.02.03
nexus 5를 위한 Android 4.4 빌드하기 1. 빌드 환경 설정.  (0) 2014.07.08
android IP 확인  (0) 2014.05.19

nexus 5를 위한 Android 4.4 빌드하기 1. 빌드 환경 설정.

nexus 5를 위한 Android 4.4 빌드하기 2. 소스코드 다운로드


http://source.android.com/source/initializing.html


안드로이드를 직접 빌드 해서 올려볼 일이 있어서 하게 된 작업.

위의 링크에 나와있는 대로 순서대로 진행해 보자.


나의 작업 환경은 다음과 같다.

ubuntu 14.04

64bit


시작해 보자.


1. JDK 설치


우선 JDK를 설치해야 한다. 안드로이드는 자바 기반이기 때문이다.

최신의 안드로이드라면 java7을 설치 하라고 한다.

시키는 대로 설치하도록 하자.

$ sudo apt-get update

$ sudo apt-get install openjdk-7-jdk


2. 필수 패키지 설치 (12.04)


안드로이드 빌드를 위해서는 여러가지 라이브러리 같은 것들이 필요하다. 그래서 이것들을 설치해야만 한다.

안드로이드는 우분투 12.04를 강추하기때문에 14.04버전을 위한 추천은 없다.

하지만 14.04나 12.04나 거기서 거기겠지... 그래도 따라한다.

맨 위에 build-essential은 이미 설치 했다면 필요 없다.

sudo apt-get install build-essential

sudo apt-get install git gnupg flex bison gperf build-essential \

  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \

  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \

  libgl1-mesa-dev g++-multilib mingw32 tofrodos \

  python-markdown libxml2-utils xsltproc zlib1g-dev:i386

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so


일단 여기까지 하면 빌드를 위한 사전 작업은 완료이다.


android로 작업을 할 때 ip주소를 확인할 때가 종종 있다.

그럴 때를 위한 명령어가 있다. 커맨드 창에 다음과 같이 입력을 해보자.

adb shell netcfg

그럼 다음과 같이 나오는데 빨간줄 그어진게 ip 주소 이다.


+ Recent posts