OLD | NEW |
| (Empty) |
1 #!/bin/bash -x | |
2 | |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 set -e | |
8 | |
9 # The script is to install Android SDK, NDK for build chromium on Android, and | |
10 # doesn't need to run as root. | |
11 | |
12 # Using Android 4.0, API Level: 14 (ice cream sandwich). The SDK package is | |
13 # about 25M. | |
14 SDK_FILE_NAME="android-sdk_r20-linux.tgz" | |
15 SDK_DOWNLOAD_URL="http://dl.google.com/android/${SDK_FILE_NAME}" | |
16 SDK_MD5SUM="22a81cf1d4a951c62f71a8758290e9bb" | |
17 | |
18 # Using "ANDROID_SDK_ROOT/tools/android list targets" to get the matching target | |
19 # id which will be loaded in simulator for testing. | |
20 # For example: the output of the listed the target could be below, and the | |
21 # 'android-13' is the SDK_TARGET_ID in this case. | |
22 # id: 9 or "android-13" | |
23 # Name: Android 3.2 | |
24 # Type: Platform | |
25 # API level: 13 | |
26 # Revision: 1 | |
27 # Skins: WXGA (default) | |
28 SDK_TARGET_ID=android-15 | |
29 | |
30 # Using NDK r7; The package is about 64M. | |
31 # *** DO NOT UPDATE THE NDK without updating the 64-bit linker changes *** | |
32 # *** at the end of this file *** | |
33 NDK_FILE_NAME="android-ndk-r7-linux-x86.tar.bz2" | |
34 NDK_DOWNLOAD_URL="http://dl.google.com/android/ndk/${NDK_FILE_NAME}" | |
35 NDK_MD5SUM="bf15e6b47bf50824c4b96849bf003ca3" | |
36 | |
37 # The temporary directory used to store the downloaded file. | |
38 TEMPDIR=$(mktemp -d) | |
39 cleanup() { | |
40 local status=${?} | |
41 trap - EXIT | |
42 rm -rf "${TEMPDIR}" | |
43 exit ${status} | |
44 } | |
45 trap cleanup EXIT | |
46 | |
47 ########################################################## | |
48 # Download and install a tgz package by wget and tar -xvf. | |
49 # The current directory is changed in this function. | |
50 # Arguments: | |
51 # local_file_name, the name of downloaded file. | |
52 # download_url, the url to download the package. | |
53 # md5, the package's md5 which could be found in download page. | |
54 # install_path, where the package should be installed. | |
55 # Returns: | |
56 # None | |
57 ########################################################## | |
58 install_dev_kit() { | |
59 local local_file_name="${1}" | |
60 local download_url="${2}" | |
61 local md5="${3}" | |
62 local install_path="${4}" | |
63 | |
64 cd "${TEMPDIR}" | |
65 wget "${download_url}" | |
66 | |
67 local computed_md5=$(md5sum "${local_file_name}" | cut -d' ' -f1) | |
68 if [[ "${computed_md5}" != "${md5}" ]]; then | |
69 echo "Downloaded ${local_file_name} has bad md5sum, which is expected" >& 2 | |
70 echo "to be ${md5} but was ${computed_md5}" >& 2 | |
71 exit 1 | |
72 fi | |
73 | |
74 echo "Install ${local_file_name}" | |
75 mv "${local_file_name}" "${install_path}" | |
76 cd "${install_path}" | |
77 tar -xf "${local_file_name}" | |
78 } | |
79 | |
80 if [[ -z "${ANDROID_SDK_ROOT}" ]]; then | |
81 echo "Please set ANDROID_SDK_ROOT to where they should installed to." >& 2 | |
82 echo "For example: /usr/local/android-sdk-linux_x86" >& 2 | |
83 exit 1 | |
84 fi | |
85 | |
86 if [[ -z "${ANDROID_NDK_ROOT}" ]]; then | |
87 echo "Please set ANDROID_NDK_ROOT to where they should installed to." >& 2 | |
88 echo "For example: /usr/local/android-ndk-r6b" >& 2 | |
89 exit 1 | |
90 fi | |
91 | |
92 # Install Android SDK if it doesn't exist. | |
93 if [[ ! -d "${ANDROID_SDK_ROOT}" ]]; then | |
94 echo 'Install ANDROID SDK ...' | |
95 (install_dev_kit "${SDK_FILE_NAME}" "${SDK_DOWNLOAD_URL}" "${SDK_MD5SUM}" \ | |
96 $(dirname "${ANDROID_SDK_ROOT}")) | |
97 fi | |
98 | |
99 # Install the target if it doesn't exist. The package installed above contains | |
100 # no platform, platform-tool or tool, all those should be installed by | |
101 # ${ANDROID_SDK_ROOT}/tools/android. | |
102 found=$("${ANDROID_SDK_ROOT}/tools/android" list targets \ | |
103 | grep "${SDK_TARGET_ID}" | wc -l) | |
104 if [[ "$found" = "0" ]]; then | |
105 # Updates the SDK by installing the necessary components. | |
106 # From current configuration, all android platforms will be installed. | |
107 # This will take a little bit long time. | |
108 echo "Install platform, platform-tool and tool ..." | |
109 | |
110 # Check the SDK revision | |
111 SDK_VER=$(sed '/^\#/d' ${ANDROID_SDK_ROOT}/tools/source.properties | \ | |
112 grep 'Pkg.Revision' |tail -n 1 | cut -d "=" -f2- | \ | |
113 sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
114 if [[ ${SDK_VER} -lt 17 ]]; then | |
115 update_flag=" -o " | |
116 else | |
117 update_flag=" --all " | |
118 fi | |
119 # Updates the SDK to latest version firstly. | |
120 "${ANDROID_SDK_ROOT}"/tools/android update sdk ${update_flag} --no-ui \ | |
121 --filter platform-tool,tool,system-image,${SDK_TARGET_ID} | |
122 fi | |
123 | |
124 # Create a Android Virtual Device named 'buildbot' with default hardware | |
125 # configuration and override the existing one, since there is no easy way to | |
126 # check whether current AVD has correct configuration and it takes almost no | |
127 # time to create a new one. Create one ARM AVD and one x86 AVD. | |
128 "${ANDROID_SDK_ROOT}/tools/android" --silent create avd --name avd_armeabi \ | |
129 --abi armeabi-v7a --target ${SDK_TARGET_ID} -c 64M --force <<< "no" | |
130 | |
131 "${ANDROID_SDK_ROOT}/tools/android" --silent create avd --name avd_x86 \ | |
132 --abi x86 --target ${SDK_TARGET_ID} -c 64M --force <<< "no" | |
133 | |
134 # Install Android NDK if it doesn't exist. | |
135 if [[ ! -d "${ANDROID_NDK_ROOT}" ]]; then | |
136 echo 'Install ANDROID NDK ...' | |
137 (install_dev_kit "${NDK_FILE_NAME}" "${NDK_DOWNLOAD_URL}" "${NDK_MD5SUM}" \ | |
138 $(dirname "${ANDROID_NDK_ROOT}")) | |
139 fi | |
140 | |
141 # Install the 64-bit linker if needed. | |
142 ROOT=$(cd "$(dirname $0)/.."; pwd) | |
143 LINKER_DIR_PREFIX="$ANDROID_NDK_ROOT/toolchains/\ | |
144 arm-linux-androideabi-4.4.3/prebuilt/linux-x86" | |
145 LINKER_DIRNAME_1="$LINKER_DIR_PREFIX/bin" | |
146 LINKER_BASENAME_1=arm-linux-androideabi-ld | |
147 LINKER_DIRNAME_2="$LINKER_DIR_PREFIX/arm-linux-androideabi/bin" | |
148 LINKER_BASENAME_2=ld | |
149 NEW_LINKER=arm-linux-androideabi-ld.e4df3e0a5bb640ccfa2f30ee67fe9b3146b152d6 | |
150 | |
151 # $1: destination directory | |
152 # $2: destination binary | |
153 function replace_linker { | |
154 local linker_dirname=$1 | |
155 local linker_basename=$2 | |
156 if [[ -f "$ROOT/third_party/aosp/$NEW_LINKER" ]]; then | |
157 if [[ -d "$linker_dirname" ]]; then | |
158 if [[ ! -f "$linker_dirname/$NEW_LINKER" ]]; then | |
159 echo "Installing linker in $linker_dirname" | |
160 cp $ROOT/third_party/aosp/$NEW_LINKER "$linker_dirname/$NEW_LINKER" | |
161 mv "$linker_dirname/$linker_basename" \ | |
162 "$linker_dirname/$linker_basename.orig" | |
163 ( cd "$linker_dirname" ; ln -s "$NEW_LINKER" "$linker_basename" ) | |
164 fi | |
165 if [[ ! -f "$linker_dirname/$NEW_LINKER" ]]; then | |
166 echo "Could not copy linker" | |
167 exit 1 | |
168 fi | |
169 fi | |
170 fi | |
171 } | |
172 | |
173 replace_linker $LINKER_DIRNAME_1 $LINKER_BASENAME_1 | |
174 replace_linker $LINKER_DIRNAME_2 $LINKER_BASENAME_2 | |
OLD | NEW |