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