LoginSignup
0
2

今更 android platform build envを構築する

Last updated at Posted at 2021-06-12

notice

https://source.android.com/setup/build/initializing?hl=en
によると

"Important: Platform development on MacOS isn't supported as of June 22, 2021."

とのことで、Mac OSでのAndroid platform buildはサポートされなくなります。。。

というわけで、情報が消えてしまっているので、試しながらまとめます。

なお、16GBのRAMが必要です!

For Mac OS

how to setup

$ xcode-select --install

Case sensitive file system:

  1. diskutil
  2. create volume with APAF, case-sensitive
  3. Reserve the size at least 200GB
$ ln -s /Volumes/android /Users/xxxx/work
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod +x ~/bin/repo

なお、 https://android.googlesource.com/new-password を開いて、表示されるscirptを実行して、.gitcookieを生成しないと、repoがうまく動きません。

$ cd ~/work/android
$ mkdir r
$ cd r
$ repo init -u https://android.googlesource.com/platform/manifest -b android11-release
$ repo sync -j 16 -c
$ tar zxvf MacOSX10.15.sdk.tar.xz
$ sudo mv MacOSX10.15.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs

上のSdkをinstall以外の方法:

build/soong/cc/config/x86_darwin_host.go
index b0344af84..ee9f8e746 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -68,6 +68,7 @@ var (
                "10.15",
                "11.0",
                "11.1",
+               "12.0",
        }
 
        darwinAvailableLibraries = append(

のようにして、ご自分の環境 (ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs)に合わせてversionのサポートを追加すればbuildできるようになります.

$ source build/envsetup.sh
$ lunch

lunchでは aosp_x86_64-eng にしないと、emulatorが起動しませんので注意・・・
( aosp_arm-eng は起動せず... )

$ ulimit -n 8192
$ make -j 8
..snip..
[100% 118384/118384] Create system-qemu.img now
removing out/target/product/generic_x86_64/system-qemu.img.qcow2
out/host/darwin-x86/bin/sgdisk --clear out/target/product/generic_x86_64/system-qemu.img

#### build completed successfully (13:58:31 (hh:mm:ss)) ####

遅い。。。

$ emulator

で起動できます.

なお、

の右側のreleaseのtag ( https://github.com/intel/haxm/releases/tag/v7.7.0 など )からinstallしておくと、高速に動作できます.

$ adb devices
$ adb shell

adb も使えます.

FAQ

$ adb kill-server; adb start-server; adb devices

For Ubuntu 18.04

https://source.android.com/setup/build/initializing?hl=en に従い、Ubuntu 18.04でbuild環境を構築する。

$ sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5-dev lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

だけでいいみたいのがあるが、これだけではできなかった。

.bashrc
export _JAVA_OPTIONS="-Xmx6000m"
$ sudo apt-get install android-tools-adb bc bison build-essential curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick libncurses5 lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-gtk3-dev libxml2 libxml2-utils lzop openjdk-8-jdk pngcrush python rsync schedtool squashfs-tools xsltproc yasm zip zlib1g-dev -y
$ sudo apt-get install android-sdk-platform-tools-common -y
$ sudo usermod -aG plugdev $LOGNAME
/etc/security/limits.conf
*		soft	nofile	65536
*              hard    nofile  65536
/etc/pam.d/common-session-noninteractive
session required        pam_limits.so
/etc/pam.d/common-session
session required        pam_limits.so
/etc/pam.d/common-nonsession
session required        pam_limits.so
/etc/security/limits.d/30-nofile.conf
#<domain>      <type>  <item>         <value>
*                hard   nofile           65536
*                soft   nofile           65536
root             hard   nofile           65536
root             soft   nofile           65536
/etc/sysctl.conf
fs.file-max = 65536

念のため、
https://qiita.com/hidenorly/items/563e65e98492f0094d3c
を参考に、swapを16GBにしました。

重要

$ repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android11-release
$ repo sync -c -j 4

数増やすとエラーになる。

$ .repo/manifests$ git log
commit 9e79d8ab6fff81b5a62df67487661663219bb063 (grafted, HEAD -> default, origin/android11-release, m/android11-release)
Author: Bill Yi <byi@google.com>
Date:   Tue Sep 8 14:05:57 2020 -0700

    Manifest for Android 11 release

な状況でしかbuild成功しませんでした。
(android-11.0.0_r40とかもだめ)

$ source ./build/envsetup.sh 
$ ulimit -n 65535
$ cd device
$ lunch aosp_x86_64-eng
$ cd ..
$ make -j 4

でしかbuild成功しませんでした。

-j 8 でも16GBでbuildだめでした (Macは大丈夫ですが)

簡単にbuildできるMacのサポートがなくなるのは非常にさみしいです。

Appendix

android - S

$ repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-12.0.0_r15

M1Max Mac Book Proで以下のようにbuildできました。

[100% 96145/96145] Target vbmeta image: out/target/product/generic/vbmeta.img

#### build completed successfully (08:27:53 (hh:mm:ss)) ####

のように、M1Maxで、Rosetta2経由で、 android-12.0.0_r15 のbuildはできました.

$ emulator
emulator: ERROR: process is translated under Rosetta. Attempting to replace emulator installation.
emulator: Replacing via command: /Volumes/android/s/prebuilts/android-emulator/darwin-x86_64/darwin-aarch64-replace.sh (downloading ~120 MB)...
curl -L https://github.com/google/android-emulator-m1-preview/releases/download/0.2/emulator-darwin-aarch64-0.2-engine-only.zip -o emulator-darwin-aarch64-0.2.zip
..snip..
$ cd /Volumes/android/s/prebuilts/android-emulator/darwin-x86_64/emulator-darwin-aarch64-0.2 
$ ./emulator

なお、dual coreのi5のMBP 2014 late (16GB)では

#### build completed successfully (06:16:22 (hh:mm:ss)) #### 

でしたので、rosetta2のパフォーマンスはcompiler用途ではいまいちです。

rust関係でerrorになったら

 ld: warning: object file (/Volumes/android/s/prebuilts/rust/darwin-x86/1.51.0/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-81013f7e2820b9f9.rlib(mulxc3.o)) was built for newer macOS version (10.13) than being linked (10.10)

のようなメッセージが出たら、もうその環境ではbuildできなくなっている

試したこと

rm -rf ~/.cargo ~/.rustup
→ダメ

export MACOSX_DEPLOYMENT_TARGET=10.13

→ダメ

repo init -b android12-release

してtagではなく、最新にしてみましたがダメでした。。。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2