forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathstudiow
executable file
·198 lines (186 loc) · 5.15 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
196
197
198
#!/usr/bin/env bash
function usage() {
echo "Usage: studiow [--clear-caches] [--clean] [--reinstall] [--profile] <project subset>"
echo
echo "OPTIONS"
echo
echo " --clear-caches"
echo " Clear generated caches (but not user settings) before launching"
echo
echo " --clean"
echo " Clear (with backup) generated files (settings, caches, etc) before launching"
echo " Also implies --clear-caches"
echo
echo " --reinstall"
echo " Remove and re-download Studio itself. Also implies --clean"
echo
echo " --profile"
echo " Enables profiling of Studio"
echo
echo "Project subsets:"
echo " m, main"
echo " Open the project subset main: non-Compose Jetpack libraries"
echo
echo " c, compose"
echo " Open the project subset compose"
echo
echo " ca, camera"
echo " Open the project subset camera"
echo
echo " f, flan"
echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation"
echo
echo " media"
echo " Open the project subset media: Media, Media2, and MediaRouter"
echo
echo " kmp"
echo " Open the project subset KMP: Projects that have KMP builds"
echo
echo " w, wear"
echo " Open the project subset for Wear OS libraries"
echo
echo " g, glance"
echo " Open the project subset for glance projects"
echo
echo
echo " native"
echo " Open the project subset for native projects"
echo
echo " a, all"
echo " Open the project subset all"
echo
exit 1
}
cd "$(dirname $0)"
subsetArg=""
clearCaches=false
cleanSettings=false
reinstall=false
projectSubset=""
profile=false
while [ "$1" != "" ]; do
arg="$1"
shift
# parse options
if [ "$arg" == "--clear-caches" ]; then
clearCaches=true
continue
fi
if [ "$arg" == "--clean" ]; then
clearCaches=true
cleanSettings=true
continue
fi
if [ "$arg" == "--reinstall" ]; then
clearCaches=true
cleanSettings=true
reinstall=true
continue
fi
if [ "$arg" == "--profile" ]; then
profile=true
continue
fi
# parse arguments
subsetArg="$arg"
newSubset=""
if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
newSubset=main
fi
if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
newSubset=compose
fi
if [ "$subsetArg" == "ca" -o "$subsetArg" == "camera" ]; then
newSubset=camera
fi
if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
newSubset=flan
fi
if [ "$subsetArg" == "media" ]; then
newSubset=media
fi
if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
newSubset=wear
fi
if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
newSubset=glance
fi
if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then
newSubset=kmp
fi
if [ "$subsetArg" == "native" ]; then
newSubset=native
fi
if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
newSubset=all
fi
if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then
newSubset=tools
fi
if [ "$subsetArg" == "wm" -o "$subsetArg" == "window" ]; then
newSubset=window
fi
if [ "$newSubset" == "" ]; then
echo "Unrecognized argument: '$subsetArg'"
usage
fi
if [ "$projectSubset" != "" ]; then
echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once"
usage
fi
projectSubset=$newSubset
done
if [ "$projectSubset" == "" ]; then
echo "Project subset is required"
usage
fi
export ANDROIDX_PROJECTS=$projectSubset
# ensures the nonexistence of a file or directory, and makes a backup
function remove() {
path="$1"
backup="$(dirname $path)/studio-backup/$(basename $path)"
if [ -e "$path" ]; then
echo "Moving $path to $backup"
rm -rf "$backup"
mkdir -p "$(dirname $backup)"
mv "$path" "$backup"
fi
}
if [ "$reinstall" == "true" ]; then
# remove Studio itself so Gradle will re-download it
rm -rf studio
fi
if [ "$profile" == "true" ]; then
PROFILE_FILE=/tmp/report.json
traceConfig="$(cd development/studio && pwd)/profile.config"
rm -f "$PROFILE_FILE"
echo "Profile file will be $PROFILE_FILE , which will be able to be loaded into chrome://tracing"
echo
echo "If you find that too many or too few function calls are included in the trace, modify $traceConfig"
echo
tracerJar="$(cd ../../prebuilts/androidx/external/com/android/tools/tracer/agent && pwd)/trace_agent.jar"
# Make sure to set _JAVA_OPTIONS before starting Gradle
export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:${tracerJar}=${traceConfig}"
fi
# remove studio-specific caches
if [ "$cleanSettings" == "true" ]; then
# make backups of files that users might have customized
remove ~/.AndroidStudioAndroidX
remove ~/.AndroidStudioAndroidXPlayground
remove ~/.android
fi
if [ "$clearCaches" == "true" ]; then
# delete (without backup) files that users won't have customized
git clean -fdX .idea/
# remove gradle caches too and build
./cleanBuild.sh -y studio
else
# If not a clean launch, then a Gradle daemon might be running.
# If profiling, we need to stop the Gradle daemon to make sure any changes to the
# profiling properties will be used.
if [ "$profile" == "true" ]; then
./gradlew --stop
fi
# ask gradle to launch studio
./gradlew :studio
fi