Cygwin에서 Android systrace 실행 문제

2014년 8월 현재, Cygwin으로 systrace를 사용하려고 하면 zlib 관련한 error가 나면서 동작하지 않는다.

$ python systrace.py -o output.html gfx input view wm am video hal dalvik
capturing trace... done
downloading trace... done

Traceback (most recent call last):
  File "systrace.py", line 286, in <module>
    main()
  File "systrace.py", line 231, in main
    decoded_chunk = dec.decompress(chunk)
zlib.error: Error -3 while decompressing: incorrect header check

AOSP project의 이 링크에 보면 문제를 해결하기 위한 patch가 올려져 있는데 comment를 보니 한동안 받아들여 지지 않다가 현재 source와 달라져서 적용할 수 없게 된 모양이다. 같은 동작을 하도록 약간만 수정해서 이렇게 고쳐 보니 좀 지저분하긴 해도 zlib error 없이 Cygwin에서 systrace를 사용할 수 있었다.

diff --git a/systrace.py b/systrace.py
index 387f413..0d3be25 100644
--- a/systrace.py
+++ b/systrace.py
@@ -205,8 +205,12 @@ def main():
       data = ''.join(data)

       # Collapse CRLFs that are added by adb shell.
-      if data.startswith('\r\n'):
-        data = data.replace('\r\n', '\n')
+      if sys.platform == 'cygwin':
+        if data.startswith('\r\r\n'):
+          data = data.replace('\r\r\n', '\n')
+      else:
+        if data.startswith('\r\n'):
+          data = data.replace('\r\n', '\n')

       # Skip the initial newline.
       data = data[1:]


Emacs에서 Android 개발 환경 사용

AOSP에는 Emacs에서 Android 개발환경을 사용할 수 있도록 몇몇 el file들을 제공하는데, platform  module build를 주로 하게 되는 나로써는 사용에 부족함이 없는 것 같다. Module build와 기본적인 ADB 조작을 지원하는 이 script들의 기능이 부족하다고 느낀다면 Android 개발환경을 보다 적극적으로 지원하는 android-mode와 같은 project를 고려해 보는것도 좋을 것이다.

buildspec.mk 설정

사실 이 기능은 그동안 사용하지 않았었는데, AOSP에서 지원하는 el script들을 사용하려면 설정해 주어야 한다. 간단한 과정을 거쳐 설정해 놓고 보니 shell에서도 사전설정 없이 ‘make target’ command만으로 build를 할 수 있어서 편하다. 대신 ‘cd $OUT’이나 ‘croot’ 같은 이동 command들을 사용할 수 없다는 것은 불편한 점이다.

<ANDROID_ROOT>/build/buildspec.mk.default file을 복사해서 환경에 맞게 수정한 다음 <ANDROID_ROOT> 위치에 놓아두면 build 명령을 내릴때 자동으로 참조된다. 기본적으로 TARGET_PRODUCT, TARGET_BUILD_VARIANT 정도만 수정하면되는데 특이한 build환경을 사용하고 있다면 나머지 항목들은 읽어보고 자신에 맞게 수정하자.

# Choose a product to build for. Look in the products directory for ones
# that work.
ifndef TARGET_PRODUCT
  TARGET_PRODUCT:=product_name
endif

# Choose a variant to build. If you don't pick one, the default is eng.
# User is what we ship. Userdebug is that, with a few flags turned on
# for debugging. Eng has lots of extra tools for development.
ifndef TARGET_BUILD_VARIANT
  TARGET_BUILD_VARIANT:=eng
endif

el file들 복사 및 설정

<ANDROID_ROOT>/development/ide/emacs/ 안에 있는 file들을 Emacs 환경 directory로 복사한 다음 해당 file이 load되도록 init file을 수정한다.

mkdir ~/.emacs.d/android.el
cp <ANDROID_ROOT>/development/ide/emacs/*.el ~/.emacs.d/android.el/ android-common.el android-compile.el android-host.el

다음을 init file에 붙여 넣으면 된다.

; Load Android tools
(add-to-list 'load-path "~/.emacs.d/android.el/")
(require 'android-host)
(require 'android-compile)


사용

편집 중인 file의 module을 build하려면 ‘M-x android-compile’을 입력 하면 된다. 그 외의 ADB에 관련한 명령어 들은 android-host.el script에 설명되어 있다.

;; C-x a a android-adb-root
;; C-x a r android-adb-remount
;; C-x a s android-adb-sync
;; C-x a b android-adb-shell-reboot-bootloader
;; C-x a f android-fastboot-flashall

[Tip] Eclipse가 시작되지 않을 때

뭔가 잘못되어서 eclipse를 실행도중에 끈 것 같은데 그 후 부터는 eclipse가 시작되지 않는 문제가 생겨서 이리 저리 검색하다가 Stackoverflow에서 이 thread를 찾았다. 실제로 내 <WORKSPACE> 경로에 있는 .metadata/.log를 보니 다음과 같은 오류 메세지가 보이고 있었다.

[WORKSPACE/.metadata/.log]

!ENTRY org.eclipse.core.jobs 4 2 2014-07-11 09:08:36.054
!MESSAGE An internal error occurred during: "Workbench early startup".
!STACK 0
java.lang.NullPointerException
at org.eclipse.core.internal.runtime.InternalPlatform.getLog(InternalPlatform.java:354)
at org.eclipse.core.runtime.Plugin.getLog(Plugin.java:291)
at org.eclipse.ui.internal.WorkbenchPlugin.log(WorkbenchPlugin.java:809)
at org.eclipse.ui.internal.EarlyStartupRunnable.handleException(EarlyStartupRunnable.java:81)
at org.eclipse.core.runtime.SafeRunner.handleException(SafeRunner.java:75)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:44)
at org.eclipse.ui.internal.Workbench$54.run(Workbench.java:2412)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
...

.metadata 아래에서 다음 경로의 .snap과 workbench.xmi file을 삭제하고 다시 eclipse를 시작해 본다.

rm .metadata/.plugins/org.eclipse.core.resources/.snap .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi