-
Notifications
You must be signed in to change notification settings - Fork 9
/
install-avd.sh
158 lines (131 loc) · 5.33 KB
/
install-avd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
source utils/colors.sh ''
source utils/print.sh ''
printUsage() {
printInfoTitle "<< USAGE ${0} >>"
printUsageTip "bash install-avd.sh ?" "print help"
printUsageTip "bash install-avd.sh install" "install avd"
printGap
}
##
# Lightweight AVD installation.
# Installs SDK tools CLI without Android Studio.
##
installAvd() {
printInfoTitle "Checking the architecture..."
printGap
local ARCH
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = 'amd64' ]; then
printInfoTitle "Detected architecture: amd64. Installing packages"
printGap
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 libstdc++6:i386 || sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 libstdc++6:i386
elif [ "$ARCH" = 'i386' ]; then
printInfoTitle "Detected architecture: i386. Passing step"
printGap
fi
printInfoTitle "Installing the G++ compiler..."
printGap
sudo apt-get install g++
printInfoTitle "Installing the Open JDK 11 and 17..."
printGap
sudo apt-get install default-jdk openjdk-11-jdk openjdk-17-jdk
printInfoTitle "Configuring the JDK..."
printGap
sudo update-alternatives --config java
local BASHRC_PATH
BASHRC_PATH="${HOME}/.bashrc"
printInfoTitle "Setting the JAVA_HOME environment variable..."
printGap
local JAVA_HOME_NEW_VALUE
JAVA_HOME_NEW_VALUE="export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')"
printInfoMessage "JAVA_HOME, new value: ${JAVA_HOME_NEW_VALUE}"
printGap
if grep -q "JAVA_HOME" "${BASHRC_PATH}"; then
local JAVA_HOME_CURRENT_VALUE
JAVA_HOME_CURRENT_VALUE=$(grep "^.*JAVA_HOME.*$" "${BASHRC_PATH}")
printWarningMessage "JAVA_HOME exists, current value: ${JAVA_HOME_CURRENT_VALUE}"
printGap
else
printInfoMessage "JAVA_HOME does not exist, setting value"
printGap
{
echo "# java jdk home"
echo "export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')"
} >>"$BASHRC_PATH"
fi
local SDK_ZIP_PATH
SDK_ZIP_PATH="${HOME}/Downloads/commandlinetools-linux-10406996_latest.zip"
printInfoTitle "Downloading (if needed), and unpacking the Android SDK Tools..."
printGap
sudo apt install wget unzip
if [ ! -f "${SDK_ZIP_PATH}" ]; then
##
# If wget fails find latest here: https://developer.android.com/studio#downloads
##
wget https://dl.google.com/android/repository/commandlinetools-linux-10406996_latest.zip -O "${SDK_ZIP_PATH}"
fi
unzip "${SDK_ZIP_PATH}" -d "${HOME}/Downloads"
printInfoTitle "Creating the Android SDK Tools directory..."
printGap
mkdir -p "${HOME}/android/sdk/cmdline-tools/latest"
printInfoTitle "Setting the ANDROID_HOME system environment variable..."
printGap
if grep -q "ANDROID_HOME" "${BASHRC_PATH}"; then
local ANDROID_HOME_CURRENT_VALUE
ANDROID_HOME_CURRENT_VALUE=$(grep "^.*ANDROID_HOME.*$" "${BASHRC_PATH}")
printWarningMessage "ANDROID_HOME exists, current value: ${ANDROID_HOME_CURRENT_VALUE}"
printGap
else
printInfoTitle "ANDROID_HOME does not exist, setting the variable..."
printGap
{
echo "# android sdk variables"
echo "export ANDROID_HOME=~/android/sdk"
} >>"$BASHRC_PATH"
fi
printInfoTitle "Copying ${HOME}/Downloads/cmdline-tools to ${ANDROID_HOME}"
printGap
cp -r "${HOME}/Downloads/cmdline-tools/bin" "${HOME}/android/sdk/cmdline-tools/latest"
cp -r "${HOME}/Downloads/cmdline-tools/lib" "${HOME}/android/sdk/cmdline-tools/latest"
cp "${HOME}/Downloads/cmdline-tools/source.properties" "${HOME}/android/sdk/cmdline-tools/latest"
cp "${HOME}/Downloads/cmdline-tools/NOTICE.txt" "${HOME}/android/sdk/cmdline-tools/latest"
printInfoTitle "Applying ${BASHRC_PATH} changes..."
printGap
# shellcheck source="$HOME"/.bashrc
# shellcheck disable=SC1091
source "$BASHRC_PATH"
printInfoTitle "Accepting the SDK manager licenses in bulk..."
printGap
yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --licenses
printInfoTitle "Installing Android SDK Platform 34 or later, Android SDK Build-Tools 34.0.0 or later, Android Support Repository, Google Repository"
printGap
"$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --install "tools" "platform-tools" "platforms;android-34" "build-tools;34.0.0" "extras;android;m2repository" "extras;google;m2repository"
printInfoTitle "Touching /root/.android/repositories.cfg file to avoid missing file error"
printGap
sudo mkdir -p /root/.android || true
sudo touch /root/.android/repositories.cfg
printInfoTitle "Updating Android sdkmanager..."
printGap
"$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --update
printInfoTitle "Installing Android images..."
printGap
"$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager "system-images;android-34;google_apis;x86_64"
printInfoTitle "Listing available targets..."
printGap
"$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" list target
printInfoTitle "Creating an AVD..."
printGap
"$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" create avd -n api34device -k "system-images;android-34;google_apis;x86_64"
printInfoTitle "Listing available AVDs..."
printGap
"$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager" list avd
printSuccessTitle "AVD has been installed successfully."
printGap
flutter doctor -v
}
if [ "$1" = "?" ]; then
printUsage
elif [ "$1" = "install" ]; then
installAvd
fi