forked from aosp-mirror/platform_frameworks_support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudiow
executable file
·195 lines (168 loc) · 5.35 KB
/
studiow
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
set -e
# This is a wrapper script that runs the specific version of Android Studio that is recommended for developing in this repository.
# (This serves a similar purpose to gradlew)
function getStudioUrl() {
propertiesFile="${scriptDir}/buildSrc/studio_versions.properties"
version="$(grep "studio_version=" ${propertiesFile} | sed 's/[^=]*=//')"
ideaMajorVersion="$(grep "idea_major_version=" ${propertiesFile} | sed 's/[^=]*=//')"
buildNumber="$(grep "studio_build_number=" ${propertiesFile} | sed 's/[^=]*=//')"
osName="$1"
extension=""
if [ "${osName}" == "linux" ]; then
extension="tar.gz"
else
extension="zip"
fi
studioUrl="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${ideaMajorVersion}.${buildNumber}-${osName}.${extension}"
echo "${studioUrl}"
}
acceptsLicenseAgreement="$1"
scriptDir="$(cd $(dirname $0) && pwd)"
projectDir=$scriptDir
tempDir="${scriptDir}/studio"
function getOsName() {
unameOutput="$(uname)"
osName=""
if [ "${unameOutput}" == "Linux" ]; then
osName="linux"
else
osName="mac"
fi
echo "${osName}"
}
osName="$(getOsName)"
studioUrl="$(getStudioUrl $osName)"
studioDestName="$(basename ${studioUrl})"
studioZipPath="${tempDir}/${studioDestName}"
studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//; s/\.tar.gz$//')"
function downloadFile() {
fromUrl="$1"
destPath="$2"
tempPath="${destPath}.tmp"
if [ -f "${destPath}" ]; then
read -r -n 1 -p "File already exists. Do you want to delete and re-download? [Y/n]? " reply
if [ ! -z "${reply}" ]; then
# Fix missing newline
echo
fi
case "${reply}" in
[yY]|"")
rm "${destPath}"
;;
*)
esac
fi
if [ -f "${destPath}" ]; then
echo "Using existing file from ${destPath}"
else
echo "Downloading ${fromUrl} to ${destPath}"
curl "${fromUrl}" > "${tempPath}"
mv "${tempPath}" "${destPath}"
fi
}
function findStudioMacAppPath() {
echo "$(find "${studioUnzippedPath}" -type d -depth 1 -name "Android Studio*.app")"
}
function getLicensePath() {
if [ "${osName}" == "mac" ]; then
appPath="$(findStudioMacAppPath)"
echo "${appPath}/Contents/Resources/LICENSE.txt"
else
echo "${studioUnzippedPath}/android-studio/LICENSE.txt"
fi
}
function checkLicenseAgreement() {
# TODO: Is there a more official way to check that the user accepts the license?
licenseAcceptedPath="${studioUnzippedPath}/STUDIOW_LICENSE_ACCEPTED"
if [ ! -f "${licenseAcceptedPath}" ]; then
if [ "${acceptsLicenseAgreement}" == "-y" ]; then
touch "${licenseAcceptedPath}"
else
read -r -n 1 -p "Do you accept the license agreement at $(getLicensePath) [Y/n]? " reply
if [ ! -z "${reply}" ]; then
# Fix missing newline
echo
fi
case "${reply}" in
[yY]|"")
touch "${licenseAcceptedPath}"
;;
*)
exit 1
;;
esac
fi
fi
}
# Temporary fix. Remove this after fixing b/135183535
function updateJvmHeapSize() {
if [ "${osName}" == "mac" ]; then
sed -i '' 's/-Xmx.*/-Xmx8g/' "$(findStudioMacAppPath)/Contents/bin/studio.vmoptions"
else
sed -i 's/-Xmx.*/-Xmx8g/' "${studioUnzippedPath}/android-studio/bin/studio64.vmoptions"
sed -i 's/-Xmx.*/-Xmx4g/' "${studioUnzippedPath}/android-studio/bin/studio.vmoptions"
fi
}
function updateStudio() {
# skip if already up-to-date
if stat "${studioUnzippedPath}" >/dev/null 2>/dev/null; then
# already up-to-date
return
fi
mkdir -p "${tempDir}"
downloadFile "${studioUrl}" "${studioZipPath}"
echo
echo "Removing previous installations"
ls "${tempDir}" | grep -v "^${studioDestName}\$" | sed "s|^|${tempDir}/|" | xargs rm -rf
echo "Unzipping"
if [ ${studioZipPath: -7} == ".tar.gz" ]; then
mkdir "${studioUnzippedPath}"
tar -xvf "${studioZipPath}" -C "${studioUnzippedPath}"
else
unzip "${studioZipPath}" -d "${studioUnzippedPath}"
fi
}
function ensureLocalPropertiesUpdated() {
testPath="${projectDir}/local.properties"
populaterCommand="./gradlew help"
if [ ! -f "${testPath}" ]; then
cd "$scriptDir"
echo "Creating $testPath by running '$populaterCommand'"
eval $populaterCommand
fi
}
# ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED environment variable prevents Studio from showing IDE
# inspection warnings for nullability issues, if the context is deprecated
# This environment variable is consumed by InteroperabilityDetector.kt
function runStudioLinux() {
studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh"
echo "$studioPath &"
env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED="true" \
"${studioPath}" "${projectDir}" &
}
function runStudioMac() {
appPath="$(findStudioMacAppPath)"
echo "open ${appPath}"
env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED="true" \
open -a "${appPath}" "${projectDir}"
}
function runStudio() {
updateJvmHeapSize
if [ "${osName}" == "mac" ]; then
runStudioMac
else
runStudioLinux
fi
}
function main() {
updateStudio
checkLicenseAgreement
ensureLocalPropertiesUpdated
runStudio
}
main