본문 바로가기
SW 개발/Android

Android 소스 최적화 (100GB에서 65GB로 줄이기)

by Kibua20 2020. 6. 12.

Android source는 Q-OS 기준으로 대략 100GB 정도의 크기이고, /.repo 가 47GB로  거의 50% 용량을 차지하고 있다. Git 전체를 다운로드 받으면 git log를 통해서 history 확인이 가능하지만, 굳이 전체 history를 확인할 필요가 없는 경우 git log 정보는 디스크 낭비이다.  예를 들어,  개발자가 commit을 이미 만든 상태에서 commit 을 반영한 system 이미지를 만드는 경우 git log 전체를 다운로드 할 필요은 없다.  또한  Android source는 Linux와 MacOS의 prebuilt tool chain 까지 포함하고 있어 Linux에서만 빌드하는 경우 Mac OS tool chain은 삭제 가능하다. 

 

Repo 와 Git 옵션을 통해서 소스양을 100.8GB → 62.5GB로 줄이는 방법을 요약하면 아래와 같다.  

 

요약: 

  • Repo 와 git clone 옵션을 통해서  Android 소스를 100.8 GB → 62.5GB인다.  (※ AOSP 빌드 결과 /out는  80GB임)
  • repo init  시  -c --depth=1 --no-tags  옵션 사용,  repo sync -c --no-tags 옵션 사용
  • Linux 에서 빌드하는 경우 Mac OS 용 tool chain을 삭제한다. 

개선 전 명령어

$ repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r36
$ repo sync -j4 -q
$ repo start android-10.0.0_r36 --all

 

개선 후 명령어

$ repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r36  -c  --depth=1 --no-tags
$ repo sync -j4  -q -c --no-tags
$ repo start android-10.0.0_r36  --all

 

AOSP Q-OS 소스 사이즈 개선 전/후 비교

Android Q-OS 소스 비교

 

1. repo init 옵션

 repo init 옵션 중에 코드 사이즈를 줄일 수 있는 옵션은 -c , --depth, --no-tags 옵션이다. 

1) -c  옵션:  working branch 만 다운로드 하는 것으로 하나의 branch에서만 코드 작업을 하는 경우 유용하다. -c  옵션 사용하는 경우 branch 간 전환은 할 수 없다. 

2) --depth 옵션:  git log 로 확인한 가능한 history 개수를 제한한다. 예를 들어,  --depth=100 으로 설정했다면 git log로 100개 까지의 history 를 다운로드 한다.  소스를 처음 받는 경우 repo init 의 depth 옵션은 git clone 시 depth 옵션으로 전달된다. 

3)  --no-tags 옵션:  tag 정보없이  소스를 다운로드 하는 것이다.  Working 소스에서 tag 가 전환이 필요 없는 경우 유용하다.

repo init 명령어 :  -c, --depth, no-tags 옵션 사용 가능

 

2. repo sync 옵션

repo ysnc 옵션에서 repo init 과 유사하게 -c 와 --no-tags 옵션을 사용할 수 있다. 

 

1) -c 옵션: 현재 설정된 branch 의 소스만 다운로드 한다.

2) --no-tags 옵션:  Tag 정보 없이 소스를 다운로드 한다. 

 

repo sync 옵션:-c 옵션과 --no-tags 옵션

 

3. Mac OS 빌드용 tool chain 삭제 

AOSP는 Linux 와 Mac OS용 tool chain이 모두 포함되어 있다. Mac OS 와 관련한 tool chain은 삭제한다. MAC OS 용 tool chain은 대략 10 GB정도이며,  /prebuilt 와  /.repo 폴더 포함되어 있다.  git을 삭제하기 때문에 main branch에서 적용할때는 주의해야 한다. 

find ./prebuilts/ -name "*darwin-x86*" -type d
find ./prebuilts/ -name "*darwin-x86*" -type d -exec rm -rf {} \;
find ./.repo -name "*darwin-x86*" -type d 
find ./.repo -name "*darwin-x86*" -type d -exec rm -rf {} \;

$ find ./prebuilts/ -name "*darwin-x86*" -type d

./prebuilts/build-tools/path/darwin-x86

./prebuilts/build-tools/darwin-x86
./prebuilts/gcc/darwin-x86
./prebuilts/android-emulator/darwin-x86_64
./prebuilts/android-emulator/darwin-x86_64/qemu/darwin-x86_64
./prebuilts/jdk/jdk8/darwin-x86
./prebuilts/jdk/jdk9/darwin-x86
./prebuilts/clang/host/darwin-x86
./prebuilts/asuite/atest/darwin-x86
./prebuilts/asuite/acloud/darwin-x86
./prebuilts/asuite/aidegen/darwin-x86
./prebuilts/gdb/darwin-x86
./prebuilts/python/darwin-x86
./prebuilts/misc/darwin-x86
./prebuilts/misc/darwin-x86_64
./prebuilts/tools/darwin-x86
./prebuilts/tools/darwin-x86_64
./prebuilts/clang-tools/darwin-x86
./prebuilts/go/darwin-x86


find ./.repo -name "*darwin-x86*" -type d
./.repo/project-objects/platform/prebuilts/gcc/darwin-x86
./.repo/project-objects/platform/prebuilts/clang/host/darwin-x86.git
./.repo/project-objects/platform/prebuilts/gdb/darwin-x86.git
./.repo/project-objects/platform/prebuilts/python/darwin-x86
./.repo/project-objects/platform/prebuilts/go/darwin-x86.git
./.repo/projects/prebuilts/gcc/darwin-x86
./.repo/projects/prebuilts/clang/host/darwin-x86.git
./.repo/projects/prebuilts/gdb/darwin-x86.git
./.repo/projects/prebuilts/python/darwin-x86
./.repo/projects/prebuilts/go/darwin-x86.git

 

<관련글>

2020/06/07 - [모바일/Android] - Android 11 (R-OS) Emulator에 설치하기

2020/06/06 - [모바일/Android] - Android 11 변경 기능 소개

2020/06/04 - [모바일/Android] - Ubuntu 20.04 에서 Android 10 빌드하기

2020/06/03 - [모바일/Android] - Android Studio 4.0 사용하기

2020/05/31 - [모바일/Android] - Android 10 (Q-OS) 소스 다운로드

2020/06/04 - [모바일/Android] - Ubuntu 20.04 에서 Android 10 빌드하기

 




댓글