OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/bash -e | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 # | |
6 # This installs Android SDK and NDK for chromium android builds. It does | |
7 # not require root. | |
8 | |
9 if [[ $1 == '--auto' ]]; then | |
10 USE_VERSION_FILE=1 | |
11 set -x | |
12 fi | |
13 | |
14 # Increment to induce bots to install updates and/or a new sdk version | |
15 SCRIPT_VERSION=1 | |
16 | |
17 if [[ -z $ANDROID_SDK_ROOT ]]; then | |
18 DEFAULT_SDK_ROOT="/usr/local/google/android-sdk-linux" | |
19 read -p "ANDROID_SDK_ROOT not set. Hit enter to use $DEFAULT_SDK_ROOT." | |
20 export ANDROID_SDK_ROOT="$DEFAULT_SDK_ROOT" | |
21 fi | |
22 | |
23 if [[ -z $ANDROID_NDK_ROOT ]]; then | |
24 DEFAULT_NDK_ROOT="/usr/local/google/android-ndk-r7" | |
25 read -p "ANDROID_NDK_ROOT not set. Hit enter to use $DEFAULT_NDK_ROOT." | |
26 export ANDROID_NDK_ROOT="$DEFAULT_NDK_ROOT" | |
27 fi | |
28 | |
29 base_dir=$(dirname $ANDROID_SDK_ROOT) | |
30 if [[ ! -d $base_dir ]]; then | |
31 echo "Base directory '$base_dir' doesn't exist. Creating..." | |
32 mkdir "$base_dir" | |
bulach
2012/07/02 10:19:41
nit: -p
Isaac (away)
2012/07/03 06:49:59
Wanted the script to try to create one level and t
| |
33 fi | |
34 | |
35 VERSION_FILE="$ANDROID_SDK_ROOT/INSTALL_SDK_VERSION" | |
36 if [[ $USE_VERSION_FILE ]]; then | |
37 if [[ -f $VERSION_FILE && $(cat "$VERSION_FILE") == $SCRIPT_VERSION ]]; then | |
38 echo "sdk / ndk up to date, not installing." | |
39 exit | |
40 fi | |
41 | |
42 rm -rf "$ANDROID_SDK_ROOT" | |
43 rm -rf "$ANDROID_NDK_ROOT" | |
44 fi | |
45 | |
46 ######################################################### | |
47 ### FUNCTION DEFINITIONS - SCRIPT CONTINUES AT BOTTOM ### | |
bulach
2012/07/02 10:19:41
:)
tbh, it'd be better to create functions for the
Isaac (away)
2012/07/03 06:49:59
Sounds good, will do.
| |
48 ######################################################### | |
49 | |
50 # Download a tarball using wget and extract it. | |
51 # Arguments: | |
52 # download_url, the url to download the package. | |
53 # md5, the expected md5 | |
54 function download_and_extract { | |
55 local download_url="$1" | |
56 local md5="$2" | |
57 local local_file="$$.$(basename $download_url)" | |
58 wget "$download_url" -O $local_file | |
59 if [[ $(md5sum $local_file | cut -d' ' -f1) != $md5 ]]; then | |
60 return 1 | |
61 fi | |
62 tar -xf $local_file | |
63 rm $local_file | |
64 } | |
65 | |
66 function install_sdk { | |
67 # Targets can be found with 'tools/android list sdk --extended' | |
68 local SDK_TARGET_ID="android-15" | |
69 local SDK_DOWNLOAD_URL="http://dl.google.com/android/android-sdk_r20-linux.tgz " | |
70 local SDK_MD5SUM="22a81cf1d4a951c62f71a8758290e9bb" | |
71 | |
72 echo 'Installing ANDROID SDK ...' | |
73 pushd $(dirname "$ANDROID_SDK_ROOT") | |
74 if [[ ! -d $ANDROID_SDK_ROOT ]]; then | |
75 download_and_extract $SDK_DOWNLOAD_URL $SDK_MD5SUM | |
76 fi | |
77 cd "$ANDROID_SDK_ROOT" | |
78 if ! tools/android list sdk --extended | grep -q "^id.*$SDK_TARGET_ID"; then | |
79 echo "SDK target $SDK_TARGET_ID already up to date, skipping sdk update" | |
80 return | |
81 fi | |
82 | |
83 # Updates the SDK by installing the necessary components. | |
84 # From current configuration, all android platforms will be installed. | |
85 echo "Installing platform, platform-tool and tool ..." | |
86 # Updates the SDK to latest version firstly. | |
87 tools/android update sdk --no-ui \ | |
88 --filter "platform-tool,tool,system-image,$SDK_TARGET_ID" | |
89 | |
90 # Create android vitual devices for ARM and x86. | |
91 # With --force this overwrites prior configurations, if they exist. | |
92 tools/android create avd --name buildbot --abi armeabi-v7a \ | |
93 --target $SDK_TARGET_ID --force <<< "no" | |
94 | |
95 tools/android create avd --name buildbot-x86 --abi x86 \ | |
96 --target $SDK_TARGET_ID --force <<< "no" | |
97 | |
98 popd | |
99 } | |
100 | |
101 function replace_binary { | |
102 local source_file=$1 | |
103 local dest_dir=$2 | |
104 local dest_basename=$3 | |
105 mv -n "$dest_dir/$dest_basename" "$dest_dir/$dest_basename.orig" | |
106 cp "$source_file" "$dest_dir/$dest_basename" | |
107 echo "$dest_basename replaced by $source_file" > $dest_dir/README.PATCH | |
108 } | |
109 | |
110 function install_ndk { | |
111 # *** Do not change without updating the 64-bit linker *** | |
112 local NDK_DOWNLOAD_URL="http://dl.google.com/android/ndk/android-ndk-r7-linux- x86.tar.bz2" | |
113 local NDK_MD5SUM="bf15e6b47bf50824c4b96849bf003ca3" | |
114 local NEW_LINKER_FILE="arm-linux-androideabi-ld.e4df3e0a5bb640ccfa2f30ee67fe9b 3146b152d6" | |
115 | |
116 if [[ -d $ANDROID_NDK_ROOT ]]; then | |
117 echo "NDK directory already exists, skipping install" | |
118 return | |
119 fi | |
120 | |
121 echo "Installing ANDROID NDK..." | |
122 local SRC_ROOT="$(cd "$(dirname $0)/.."; pwd)" | |
123 pushd $(dirname "$ANDROID_NDK_ROOT") | |
124 download_and_extract "$NDK_DOWNLOAD_URL" $NDK_MD5SUM | |
125 | |
126 echo "Replacing the NDK linker..." | |
127 local NEW_LINKER="$SRC_ROOT/third_party/aosp/$NEW_LINKER_FILE" | |
128 local LINKER_BASE_DIR="toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x 86" | |
129 replace_binary "$NEW_LINKER" "$LINKER_BASE_DIR/bin" "arm-linux-androideabi-ld" | |
130 replace_binary "$NEW_LINKER" "$LINKER_BASE_DIR/arm-linux-androideabi/bin" "ld" | |
131 popd | |
132 } | |
133 | |
134 install_sdk | |
135 install_ndk | |
136 echo "$SCRIPT_VERSION" > "$VERSION_FILE" | |
OLD | NEW |