OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash -e |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 set -e | 7 # Script to install everything needed to build chromium on android that |
| 8 # requires sudo privileges. |
| 9 # See http://code.google.com/p/chromium/wiki/AndroidBuildInstructions |
8 | 10 |
9 # The script is to install Android SDK, NDK for build chromium on Android, and | 11 DOWNLOAD_URL="http://ftp.us.debian.org/debian/pool/non-free/s/sun-java6" |
10 # doesn't need to run as root. | |
11 | 12 |
12 # Using Android 4.0, API Level: 14 (ice cream sandwich). The SDK package is | 13 BIN_FILE_NAME="sun-java6-bin_6.26-0squeeze1_amd64.deb" |
13 # about 25M. | 14 JRE_FILE_NAME="sun-java6-jre_6.26-0squeeze1_all.deb" |
14 SDK_FILE_NAME="android-sdk_r16-linux.tgz" | 15 JDK_FILE_NAME="sun-java6-jdk_6.26-0squeeze1_amd64.deb" |
15 SDK_DOWNLOAD_URL="http://dl.google.com/android/${SDK_FILE_NAME}" | |
16 SDK_MD5SUM="3ba457f731d51da3741c29c8830a4583" | |
17 | 16 |
18 # Using "ANDROID_SDK_ROOT/tools/android list targets" to get the matching target | 17 if ! uname -m | egrep -q "i686|x86_64"; then |
19 # id which will be loaded in simulator for testing. | 18 echo "Only x86 architectures are currently supported" >&2 |
20 # For example: the output of the listed the target could be below, and the | 19 exit |
21 # 'android-13' is the SDK_TARGET_ID in this case. | 20 fi |
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-14 | |
29 | 21 |
30 # Using NDK r7; The package is about 64M. | 22 if [ "x$(id -u)" != x0 ]; then |
31 # *** DO NOT UPDATE THE NDK without updating the 64-bit linker changes *** | 23 echo "Running as non-root user." |
32 # *** at the end of this file *** | 24 echo "You might have to enter your password one or more times for 'sudo'." |
33 NDK_FILE_NAME="android-ndk-r7-linux-x86.tar.bz2" | 25 echo |
34 NDK_DOWNLOAD_URL="http://dl.google.com/android/ndk/${NDK_FILE_NAME}" | 26 fi |
35 NDK_MD5SUM="bf15e6b47bf50824c4b96849bf003ca3" | 27 |
| 28 sudo apt-get update |
36 | 29 |
37 # The temporary directory used to store the downloaded file. | 30 # The temporary directory used to store the downloaded file. |
38 TEMPDIR=$(mktemp -d) | 31 TEMPDIR=$(mktemp -d) |
39 cleanup() { | 32 cleanup() { |
40 local status=${?} | 33 local status=${?} |
41 trap - EXIT | 34 trap - EXIT |
42 rm -rf "${TEMPDIR}" | 35 rm -rf "${TEMPDIR}" |
43 exit ${status} | 36 exit ${status} |
44 } | 37 } |
45 trap cleanup EXIT | 38 trap cleanup EXIT |
46 | 39 |
47 ########################################################## | 40 ########################################################## |
48 # Download and install a tgz package by wget and tar -xvf. | 41 # Download (i.e. wget) and install debian package. |
49 # The current directory is changed in this function. | 42 # The current directory is changed in this function. |
50 # Arguments: | 43 # Arguments: |
51 # local_file_name, the name of downloaded file. | 44 # file_name |
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: | 45 # Returns: |
56 # None | 46 # None |
57 ########################################################## | 47 ########################################################## |
58 install_dev_kit() { | 48 install_deb_pkg() { |
59 local local_file_name="${1}" | 49 local file_name="${1}" |
60 local download_url="${2}" | 50 local download_url="${DOWNLOAD_URL}/${file_name}" |
61 local md5="${3}" | |
62 local install_path="${4}" | |
63 | 51 |
64 cd "${TEMPDIR}" | 52 cd "${TEMPDIR}" |
65 wget "${download_url}" | 53 wget "${download_url}" |
66 | 54 |
67 local computed_md5=$(md5sum "${local_file_name}" | cut -d' ' -f1) | 55 echo "Install ${file_name}" |
68 if [[ "${computed_md5}" != "${md5}" ]]; then | 56 sudo dpkg -i "${file_name}" |
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 -xvf "${local_file_name}" | |
78 } | 57 } |
79 | 58 |
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 | 59 |
86 if [[ -z "${ANDROID_NDK_ROOT}" ]]; then | 60 # Install ant |
87 echo "Please set ANDROID_NDK_ROOT to where they should installed to." >& 2 | 61 sudo apt-get install python-pexpect ant |
88 echo "For example: /usr/local/android-ndk-r6b" >& 2 | |
89 exit 1 | |
90 fi | |
91 | 62 |
92 # Install Android SDK if it doesn't exist. | 63 # Install sun-java6-bin |
93 if [[ ! -d "${ANDROID_SDK_ROOT}" ]]; then | 64 install_deb_pkg "${BIN_FILE_NAME}" |
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 | 65 |
99 # Install the target if it doesn't exist. The package installed above contains | 66 # Install sun-java6-jre |
100 # no platform, platform-tool or tool, all those should be installed by | 67 install_deb_pkg "${JRE_FILE_NAME}" |
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 | 68 |
110 "${ANDROID_SDK_ROOT}"/tools/android update sdk -o --no-ui \ | 69 # Install sun-java6-jdk |
111 --filter platform,platform-tool,tool,system-image | 70 install_deb_pkg "${JDK_FILE_NAME}" |
112 fi | |
113 | 71 |
114 # Create a Android Virtual Device named 'buildbot' with default hardware | 72 # Switch version of Java to java-6-sun |
115 # configuration and override the existing one, since there is no easy way to | 73 sudo update-java-alternatives -s java-6-sun |
116 # check whether current AVD has correct configuration and it takes almost no | |
117 # time to create a new one. | |
118 "${ANDROID_SDK_ROOT}/tools/android" --silent create avd --name buildbot \ | |
119 --target ${SDK_TARGET_ID} --force <<< "no" | |
120 | 74 |
121 # Install Android NDK if it doesn't exist. | 75 echo "install-build-deps-android.sh complete." |
122 if [[ ! -d "${ANDROID_NDK_ROOT}" ]]; then | |
123 echo 'Install ANDROID NDK ...' | |
124 (install_dev_kit "${NDK_FILE_NAME}" "${NDK_DOWNLOAD_URL}" "${NDK_MD5SUM}" \ | |
125 $(dirname "${ANDROID_NDK_ROOT}")) | |
126 fi | |
127 | |
128 # Install the 64-bit linker if needed. | |
129 ROOT=$(cd "$(dirname $0)/.."; pwd) | |
130 LINKER_DIR_PREFIX="$ANDROID_NDK_ROOT/toolchains/\ | |
131 arm-linux-androideabi-4.4.3/prebuilt/linux-x86" | |
132 LINKER_DIRNAME_1="$LINKER_DIR_PREFIX/bin" | |
133 LINKER_BASENAME_1=arm-linux-androideabi-ld | |
134 LINKER_DIRNAME_2="$LINKER_DIR_PREFIX/arm-linux-androideabi/bin" | |
135 LINKER_BASENAME_2=ld | |
136 NEW_LINKER=arm-linux-androideabi-ld.e4df3e0a5bb640ccfa2f30ee67fe9b3146b152d6 | |
137 | |
138 # $1: destination directory | |
139 # $2: destination binary | |
140 function replace_linker { | |
141 local linker_dirname=$1 | |
142 local linker_basename=$2 | |
143 if [[ -f "$ROOT/third_party/aosp/$NEW_LINKER" ]]; then | |
144 if [[ -d "$linker_dirname" ]]; then | |
145 if [[ ! -f "$linker_dirname/$NEW_LINKER" ]]; then | |
146 echo "Installing linker in $linker_dirname" | |
147 cp $ROOT/third_party/aosp/$NEW_LINKER "$linker_dirname/$NEW_LINKER" | |
148 mv "$linker_dirname/$linker_basename" \ | |
149 "$linker_dirname/$linker_basename.orig" | |
150 ( cd "$linker_dirname" ; ln -s "$NEW_LINKER" "$linker_basename" ) | |
151 fi | |
152 if [[ ! -f "$linker_dirname/$NEW_LINKER" ]]; then | |
153 echo "Could not copy linker" | |
154 exit 1 | |
155 fi | |
156 fi | |
157 fi | |
158 } | |
159 | |
160 replace_linker $LINKER_DIRNAME_1 $LINKER_BASENAME_1 | |
161 replace_linker $LINKER_DIRNAME_2 $LINKER_BASENAME_2 | |
OLD | NEW |