| #!/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() { |
| version="3.3.0.17" |
| ideaMajorVersion="182" |
| buildNumber="5138683" |
| osName="$1" |
| studioUrl="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${ideaMajorVersion}.${buildNumber}-${osName}.zip" |
| 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$//')" |
| |
| function downloadFile() { |
| fromUrl="$1" |
| destPath="$2" |
| tempPath="${destPath}.tmp" |
| echo "Downloading ${fromUrl} to ${destPath}" |
| curl "${fromUrl}" > "${tempPath}" |
| mv "${tempPath}" "${destPath}" |
| } |
| |
| function checkLicenseAgreement() { |
| # TODO: Is there a more official way to check that the user accepts the license? |
| if [ "${acceptsLicenseAgreement}" != "-y" ]; then |
| echo "Do you accept the license agreement at ${studioUnzippedPath}/android-studio/LICENSE.txt ?" |
| echo "If you do, then rerun this script with a '-y' argument" |
| exit 1 |
| fi |
| } |
| |
| function updateStudio() { |
| # skip if already up-to-date |
| if stat "${studioZipPath}" >/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" |
| unzip "${studioZipPath}" -d "${studioUnzippedPath}" |
| } |
| |
| 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" \ |
| "${studioPath}" "${projectDir}" & |
| } |
| |
| function runStudioMac() { |
| studioPath="${studioUnzippedPath}/Android Studio.app" |
| echo "open ${studioPath}" |
| env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \ |
| STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \ |
| open -a "${studioPath}" "${projectDir}" |
| } |
| |
| function runStudio() { |
| if [ "${osName}" == "mac" ]; then |
| runStudioMac |
| else |
| runStudioLinux |
| fi |
| } |
| |
| function main() { |
| updateStudio |
| checkLicenseAgreement |
| runStudio |
| } |
| |
| main |