1
1
#! /bin/bash
2
2
set -e
3
+ set -m
3
4
4
5
# This is a wrapper script that runs the specific version of Android Studio that is recommended for developing in this repository.
5
6
# (This serves a similar purpose to gradlew)
7
+ #
8
+ # NOTE: if you are changing this file, consider applying the changes to ../studiow, used for the main AndroidX project.
6
9
7
10
8
- function getStudioUrl() {
9
- propertiesFile=" ${scriptDir} /studio_versions.properties"
11
+ function getPrebuiltStudioZipPath() {
10
12
version=" $( grep " studio_version=" ${propertiesFile} | sed ' s/[^=]*=//' ) "
11
13
ideaMajorVersion=" $( grep " idea_major_version=" ${propertiesFile} | sed ' s/[^=]*=//' ) "
12
14
buildNumber=" $( grep " studio_build_number=" ${propertiesFile} | sed ' s/[^=]*=//' ) "
@@ -16,8 +18,8 @@ function getStudioUrl() {
16
18
else
17
19
extension=" zip"
18
20
fi
19
- studioUrl= " https://dl.google.com/dl/android/studio/ide-zips/ ${version} /android-studio-ide- ${ideaMajorVersion} . ${buildNumber} - ${osName} . ${extension} "
20
- echo " ${studioUrl } "
21
+
22
+ echo " ${scriptDir} /androidx_prebuilts/androidx/studio/android-studio-ide- ${ideaMajorVersion} . ${buildNumber} - ${osName} . ${extension }"
21
23
}
22
24
23
25
acceptsLicenseAgreement=" $1 "
@@ -35,10 +37,20 @@ function getOsName() {
35
37
echo " ${osName} "
36
38
}
37
39
osName=" $( getOsName) "
38
- studioUrl=" $( getStudioUrl $osName ) "
39
- studioDestName=" $( basename ${studioUrl} ) "
40
- studioZipPath=" ${tempDir} /${studioDestName} "
41
- studioUnzippedPath=" $( echo ${studioZipPath} | sed ' s/\.zip$//' | sed ' s/\.tar.gz$//' ) "
40
+ propertiesFile=" ${scriptDir} /studio_versions.properties"
41
+ prebuiltStudioZipPath=" $( getPrebuiltStudioZipPath $osName ) "
42
+ studioDestName=" $( basename ${prebuiltStudioZipPath} ) "
43
+ studioUnzippedPath=" ${tempDir} /${studioDestName} "
44
+ studioUnzippedPath=" $( echo ${studioUnzippedPath} | sed ' s/\.zip$//' | sed ' s/\.tar.gz$//' ) "
45
+
46
+ # The version of AGP we should override with - may be empty if we should just use the default
47
+ # version specified in AndroidX. See ui/studio_versions.properties.
48
+ agp_override=" $( grep " agp_override=" ${propertiesFile} | sed ' s/[^=]*=//' ) "
49
+
50
+ # Set the env variable if we have a valid version to override with, else noop
51
+ GRADLE_PLUGIN_VERSION_OVERRIDE=" "
52
+ [ ! -z " $agp_override " ] && GRADLE_PLUGIN_VERSION_OVERRIDE=" GRADLE_PLUGIN_VERSION=${agp_override} "
53
+
42
54
43
55
function error_exit {
44
56
echo " $1 " >&2 # # Send message to stderr.
@@ -115,6 +127,16 @@ function checkLicenseAgreement() {
115
127
fi
116
128
}
117
129
130
+ # Temporary fix. Remove this after fixing b/135183535
131
+ function updateJvmHeapSize() {
132
+ if [ " ${osName} " == " mac" ]; then
133
+ sed -i ' ' ' s/-Xmx.*/-Xmx8g/' " $( findStudioMacAppPath) /Contents/bin/studio.vmoptions"
134
+ else
135
+ sed -i ' s/-Xmx.*/-Xmx8g/' " ${studioUnzippedPath} /android-studio/bin/studio64.vmoptions"
136
+ sed -i ' s/-Xmx.*/-Xmx4g/' " ${studioUnzippedPath} /android-studio/bin/studio.vmoptions"
137
+ fi
138
+ }
139
+
118
140
function updateStudio() {
119
141
# skip if already up-to-date
120
142
if stat " ${studioUnzippedPath} " > /dev/null 2> /dev/null; then
@@ -123,73 +145,79 @@ function updateStudio() {
123
145
fi
124
146
125
147
mkdir -p " ${tempDir} "
126
- downloadFile " ${studioUrl} " " ${studioZipPath} "
127
- echo
128
148
129
149
echo " Removing previous installations"
130
150
ls " ${tempDir} " | grep -v " ^${studioDestName} \$ " | sed " s|^|${tempDir} /|" | xargs rm -rf
131
151
132
152
echo " Unzipping"
133
153
if [ " ${osName} " == " linux" ]; then
134
154
mkdir $studioUnzippedPath
135
- tar -xzf " ${studioZipPath } " --directory " ${studioUnzippedPath} "
155
+ tar -xzf " ${prebuiltStudioZipPath } " --directory " ${studioUnzippedPath} "
136
156
else
137
- unzip " ${studioZipPath } " -d " ${studioUnzippedPath} "
157
+ unzip " ${prebuiltStudioZipPath } " -d " ${studioUnzippedPath} "
138
158
fi
139
159
}
140
160
141
- function ensureComposeAt() {
142
- pluginPath=$1
143
- copyOption=$2
144
- idePluginJar=" $pluginPath /r4a-ide-plugin.jar"
145
- compilerPluginJar=" $pluginPath /r4a-compiler-plugin.jar"
146
- compilerPluginJarOutput=" androidx_prebuilts/out/ui/build/support_repo/androidx/compose/compose-plugin-cli/1.0.0-alpha01/compose-plugin-cli-1.0.0-alpha01.jar"
147
- idePluginJarOutput=" androidx_prebuilts/out/ui/build/support_repo/androidx/compose/compose-plugin-ide/1.0.0-alpha01/compose-plugin-ide-1.0.0-alpha01.jar"
148
- if [ ! -e " $idePluginJarOutput " ] || [ ! -e " $compilerPluginJarOutput " ]
149
- then
150
- echo " Building compose plugin"
151
- ./gradlew :compose-plugin-ide:assemble :compose-plugin-cli:ideVersion
161
+ # Copies the built compose-ide-plugin to the plugin directory of the studio installation. This
162
+ # ensures that the compose plugin is used at startup
163
+ function updateComposeIdePlugin() {
164
+ if [ " ${osName} " == " mac" ]; then
165
+ composeIdePluginDirectory=" $( findStudioMacAppPath) /Contents/plugins/compose-ide-plugin/"
166
+ else
167
+ composeIdePluginDirectory=" ${studioUnzippedPath} /android-studio/plugins/"
152
168
fi
153
- cp $copyOption " $compilerPluginJarOutput " " $compilerPluginJar "
154
- cp $copyOption " $idePluginJarOutput " " $idePluginJar "
155
- }
169
+ # this is the idea sandbox directory that the compose ide plugin is located in
170
+ composePluginDirectory=" ${projectDir} /androidx_prebuilts/out/ui/compose/compose-ide-plugin/build/idea-sandbox/plugins/compose-ide-plugin/"
156
171
157
- function ensureComposeLinux() {
158
- ensureComposeAt " ${studioUnzippedPath} /android-studio/plugins/Kotlin/lib" " -u"
159
- }
160
-
161
- function ensureComposeMac() {
162
- ensureComposeAt " $( findStudioMacAppPath) /Contents/plugins/Kotlin/lib"
172
+ echo " "
173
+ echo " Copying compose-ide-plugin to $composeIdePluginDirectory "
174
+ echo " "
175
+ mkdir -p " ${composeIdePluginDirectory} "
176
+ cp -f -R " ${composePluginDirectory} " " ${composeIdePluginDirectory} "
163
177
}
164
178
165
179
function ensureCompose() {
166
- # ensure compose plugin is up-to-date
167
- if [ " ${osName} " == " mac" ]; then
168
- ensureComposeMac
169
- else
170
- ensureComposeLinux
171
- fi
180
+ # This gradle command will prepare a sandbox directory that we can point studio to that will
181
+ # have all of the correct structure to load the compose plugin
182
+ ${scriptDir} /gradlew -p ${projectDir} :compose:compose-ide-plugin:prepareSandbox
172
183
}
173
184
185
+ # ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED environment variable prevents Studio from showing IDE
186
+ # inspection warnings for nullability issues, if the context is deprecated
187
+ # This environment variable is consumed by InteroperabilityDetector.kt
188
+
174
189
function runStudioLinux() {
175
190
studioPath=" ${studioUnzippedPath} /android-studio/bin/studio.sh"
176
- echo " $studioPath &"
191
+ updateComposeIdePlugin
192
+
193
+ echo " "
194
+ echo " Launching Studio"
195
+ # Override AGP version overridden because compose studio is behind androidx studio
177
196
env STUDIO_PROPERTIES=" ${projectDir} /idea.properties" \
178
197
STUDIO_VM_OPTIONS=" ${projectDir} /../development/studio/studio.vmoptions" \
179
- KOTLIN_OVERRIDE=" 1.3.30-compose-20190503" \
198
+ ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED=" true" \
199
+ KOTLIN_OVERRIDE=" 1.3.50-compose-20190806" \
200
+ $GRADLE_PLUGIN_VERSION_OVERRIDE \
180
201
" ${studioPath} " " ${projectDir} " &
181
202
}
182
203
183
204
function runStudioMac() {
184
205
appPath=" $( findStudioMacAppPath) "
185
- echo " open ${appPath} "
206
+ updateComposeIdePlugin
207
+
208
+ echo " "
209
+ echo " Launching Studio"
210
+ # Override AGP version overridden because compose studio is behind androidx studio
186
211
env STUDIO_PROPERTIES=" ${projectDir} /idea.properties" \
187
212
STUDIO_VM_OPTIONS=" ${projectDir} /../development/studio/studio.vmoptions" \
188
- KOTLIN_OVERRIDE=" 1.3.30-compose-20190503" \
213
+ ANDROID_LINT_NULLNESS_IGNORE_DEPRECATED=" true" \
214
+ KOTLIN_OVERRIDE=" 1.3.50-compose-20190806" \
215
+ $GRADLE_PLUGIN_VERSION_OVERRIDE \
189
216
open -a " ${appPath} " " ${projectDir} "
190
217
}
191
218
192
219
function runStudio() {
220
+ updateJvmHeapSize
193
221
if [ " ${osName} " == " mac" ]; then
194
222
runStudioMac
195
223
else
0 commit comments