blob: 213da892127b0b534d9a75e20d2d4f036c0b9ceb [file] [log] [blame]
Alan Viverettea693ece2020-11-17 16:23:42 -05001#!/usr/bin/env bash
Alan Viverettea693ece2020-11-17 16:23:42 -05002
Jeff Gastond25425c2020-12-02 09:53:57 -05003function usage() {
Jeff Gaston05651442022-01-26 12:56:58 -05004 echo "Usage: studiow [--clear-caches] [--clean] [--reinstall] [--profile] <project subset>"
Jeff Gaston1db6bb82020-12-22 13:12:23 -05005 echo
6 echo "OPTIONS"
Jeff Gaston05651442022-01-26 12:56:58 -05007 echo
8 echo " --clear-caches"
9 echo " Clear generated caches (but not user settings) before launching"
10 echo
Jeff Gaston1db6bb82020-12-22 13:12:23 -050011 echo " --clean"
12 echo " Clear (with backup) generated files (settings, caches, etc) before launching"
Jeff Gaston05651442022-01-26 12:56:58 -050013 echo " Also implies --clear-caches"
Jeff Gaston1db6bb82020-12-22 13:12:23 -050014 echo
15 echo " --reinstall"
16 echo " Remove and re-download Studio itself. Also implies --clean"
Jeff Gaston05651442022-01-26 12:56:58 -050017 echo
Jeff Gaston616585c2021-12-10 12:27:27 -050018 echo " --profile"
19 echo " Enables profiling of Studio"
Jeff Gastond25425c2020-12-02 09:53:57 -050020 echo
21 echo "Project subsets:"
22 echo " m, main"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050023 echo " Open the project subset main: non-Compose Jetpack libraries"
Jeff Gastond25425c2020-12-02 09:53:57 -050024 echo
25 echo " c, compose"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050026 echo " Open the project subset compose"
Jeff Gastond25425c2020-12-02 09:53:57 -050027 echo
Aurimas Liutikasbf1dfd42022-07-06 13:35:35 -070028 echo " ca, camera"
29 echo " Open the project subset camera"
30 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050031 echo " f, flan"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050032 echo " Open the project subset flan: Fragment, Lifecycle, Activity, and Navigation"
Jeff Gastond25425c2020-12-02 09:53:57 -050033 echo
Gyumin Simff92d182021-02-02 19:27:59 +090034 echo " media"
35 echo " Open the project subset media: Media, Media2, and MediaRouter"
36 echo
Yigit Boyarf08b9a02022-06-02 09:16:59 -070037 echo " kmp"
38 echo " Open the project subset KMP: Projects that have KMP builds"
39 echo
Flavio Lerda726911b2021-01-18 18:15:06 +000040 echo " w, wear"
41 echo " Open the project subset for Wear OS libraries"
42 echo
Zak Cohenb87e89a2022-02-18 14:24:13 -080043 echo " g, glance"
44 echo " Open the project subset for glance projects"
45 echo
Fred Sladkeye82df612022-07-14 14:50:36 -040046 echo
47 echo " native"
Fred Sladkey8478a142022-08-30 17:27:22 -040048 echo " Open the project subset for native projects"
Fred Sladkeye82df612022-07-14 14:50:36 -040049 echo
Jeff Gastond25425c2020-12-02 09:53:57 -050050 echo " a, all"
Jeff Gaston4ac74c32021-01-29 12:12:20 -050051 echo " Open the project subset all"
Jeff Gastond25425c2020-12-02 09:53:57 -050052 echo
53 exit 1
54}
55
Jeff Gaston1db6bb82020-12-22 13:12:23 -050056cd "$(dirname $0)"
57
58subsetArg=""
Jeff Gaston05651442022-01-26 12:56:58 -050059clearCaches=false
60cleanSettings=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050061reinstall=false
62projectSubset=""
Jeff Gaston616585c2021-12-10 12:27:27 -050063profile=false
Jeff Gaston1db6bb82020-12-22 13:12:23 -050064while [ "$1" != "" ]; do
65 arg="$1"
66 shift
67 # parse options
Jeff Gaston05651442022-01-26 12:56:58 -050068 if [ "$arg" == "--clear-caches" ]; then
69 clearCaches=true
70 continue
71 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050072 if [ "$arg" == "--clean" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050073 clearCaches=true
74 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050075 continue
76 fi
77 if [ "$arg" == "--reinstall" ]; then
Jeff Gaston05651442022-01-26 12:56:58 -050078 clearCaches=true
79 cleanSettings=true
Jeff Gaston1db6bb82020-12-22 13:12:23 -050080 reinstall=true
81 continue
82 fi
Jeff Gaston616585c2021-12-10 12:27:27 -050083 if [ "$arg" == "--profile" ]; then
84 profile=true
85 continue
86 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050087 # parse arguments
88 subsetArg="$arg"
89 newSubset=""
90 if [ "$subsetArg" == "m" -o "$subsetArg" == "main" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050091 newSubset=main
Jeff Gaston1db6bb82020-12-22 13:12:23 -050092 fi
93 if [ "$subsetArg" == "c" -o "$subsetArg" == "compose" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -050094 newSubset=compose
Jeff Gaston1db6bb82020-12-22 13:12:23 -050095 fi
Aurimas Liutikasbf1dfd42022-07-06 13:35:35 -070096 if [ "$subsetArg" == "ca" -o "$subsetArg" == "camera" ]; then
97 newSubset=camera
98 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -050099 if [ "$subsetArg" == "f" -o "$subsetArg" == "flan" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500100 newSubset=flan
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500101 fi
Gyumin Simff92d182021-02-02 19:27:59 +0900102 if [ "$subsetArg" == "media" ]; then
103 newSubset=media
104 fi
Flavio Lerda726911b2021-01-18 18:15:06 +0000105 if [ "$subsetArg" == "w" -o "$subsetArg" == "wear" ]; then
106 newSubset=wear
107 fi
Zak Cohenb87e89a2022-02-18 14:24:13 -0800108 if [ "$subsetArg" == "g" -o "$subsetArg" == "glance" ]; then
109 newSubset=glance
110 fi
Yigit Boyarf08b9a02022-06-02 09:16:59 -0700111 if [ "$subsetArg" == "k" -o "$subsetArg" == "kmp" ]; then
112 newSubset=kmp
113 fi
Fred Sladkeye82df612022-07-14 14:50:36 -0400114 if [ "$subsetArg" == "native" ]; then
115 newSubset=native
116 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500117 if [ "$subsetArg" == "a" -o "$subsetArg" == "all" ]; then
Jeff Gaston4ac74c32021-01-29 12:12:20 -0500118 newSubset=all
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500119 fi
David Saffc4b29f22022-05-19 12:23:37 -0400120 if [ "$subsetArg" == "t" -o "$subsetArg" == "tools" ]; then
121 newSubset=tools
122 fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500123 if [ "$newSubset" == "" ]; then
124 echo "Unrecognized argument: '$subsetArg'"
125 usage
126 fi
127 if [ "$projectSubset" != "" ]; then
128 echo "Unrecognized argument '$subsetArg', cannot specify project subset more than once"
129 usage
130 fi
131 projectSubset=$newSubset
132done
133
134if [ "$projectSubset" == "" ]; then
135 echo "Project subset is required"
Jeff Gastond25425c2020-12-02 09:53:57 -0500136 usage
137fi
138
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500139export ANDROIDX_PROJECTS=$projectSubset
140
141# ensures the nonexistence of a file or directory, and makes a backup
142function remove() {
143 path="$1"
144 backup="$(dirname $path)/studio-backup/$(basename $path)"
145 if [ -e "$path" ]; then
146 echo "Moving $path to $backup"
Flavio Lerda833bae42021-11-11 15:55:34 +0000147 rm -rf "$backup"
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500148 mkdir -p "$(dirname $backup)"
149 mv "$path" "$backup"
150 fi
151}
152
153if [ "$reinstall" == "true" ]; then
154 # remove Studio itself so Gradle will re-download it
Flavio Lerda833bae42021-11-11 15:55:34 +0000155 rm -rf studio
Jeff Gastond25425c2020-12-02 09:53:57 -0500156fi
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500157
Jeff Gaston616585c2021-12-10 12:27:27 -0500158if [ "$profile" == "true" ]; then
159 PROFILE_FILE=/tmp/report.json
160 traceConfig="$(cd development/studio && pwd)/profile.config"
161 rm -f "$PROFILE_FILE"
162 echo "Profile file will be $PROFILE_FILE , which will be able to be loaded into chrome://tracing"
163 echo
164 echo "If you find that too many or too few function calls are included in the trace, modify $traceConfig"
165 echo
166 tracerJar="$(cd ../../prebuilts/androidx/external/com/android/tools/tracer/agent && pwd)/trace_agent.jar"
167 # Make sure to set _JAVA_OPTIONS before starting Gradle
168 export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:${tracerJar}=${traceConfig}"
169fi
170
Jeff Gaston05651442022-01-26 12:56:58 -0500171# remove studio-specific caches
172if [ "$cleanSettings" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500173 # make backups of files that users might have customized
174 remove ~/.AndroidStudioAndroidX
175 remove ~/.AndroidStudioAndroidXPlayground
176 remove ~/.android
Jeff Gaston05651442022-01-26 12:56:58 -0500177fi
178
179if [ "$clearCaches" == "true" ]; then
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500180 # delete (without backup) files that users won't have customized
181 git clean -fdX .idea/
Jeff Gaston616585c2021-12-10 12:27:27 -0500182
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500183 # remove gradle caches too and build
184 ./cleanBuild.sh -y studio
185else
Jeff Gaston616585c2021-12-10 12:27:27 -0500186 # If not a clean launch, then a Gradle daemon might be running.
187 # If profiling, we need to stop the Gradle daemon to make sure any changes to the
188 # profiling properties will be used.
189 if [ "$profile" == "true" ]; then
190 ./gradlew --stop
191 fi
192
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500193 # ask gradle to launch studio
Aurimas Liutikas0db05722021-07-20 13:06:27 -0700194 ./gradlew :studio
Jeff Gaston1db6bb82020-12-22 13:12:23 -0500195fi