• 3

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

So everyone loves Android Studio's awesome portability, don't they?

I've got the SDK and all its components installed on a portable drive, and can use it anywhere. A quick Powershell script is all I need to get it up and running. The script sets all of my environmental variables, and launches the Studio and an emulator saved on my disk.

But... Every time the Studio is launched in a new environment (like a new computer), it starts with its built in Setup Wizard. Annoying. So, if I cancel the setup, I'm prompted with an option to skip the wizard on the next launch. After selecting this option, The studio launches fine.

Can the community help me with overiding the setup wizard on the first launch? Here's the script:

#                                                                                       #
#                       Portable Android SDK Environment Setup                          #
#                                 Powershell Script                                     #
#                                                                                       #
#                                   By: sh7411usa                                       #
#                                                                                       #
#                      For Use With Portable Drive Installation                         #
#                                                                                       #
#                                                                                       #

#Configure Execution Policy
Set-ExecutionPolicy Bypass -Scope Process -Force

#Display Welcome to User
Write-Output ""
Write-Output "**************************************************************************"
Write-Output "**************************************************************************"
Write-Output "**                                                                      **"
Write-Output "**                                                                      **"
Write-Output "**                    Android SDK Environment Setup                     **"
Write-Output "**                                                                      **"
Write-Output "**                                                                      **"
Write-Output "**************************************************************************"
Write-Output "**************************************************************************"
Write-Output `n

#Advise of Execution Policy
$outStr = (get-ExecutionPolicy) | Out-String
Write-Host -NoNewline "Checking Execution Policy... "
Write-Host $outStr

#Set Working Directory (containing path to Android SDK installation):
$BpathTo = (Get-Item -Path ".\").FullName

#Update for User Specific data, (usually found under "C:\Users\User\"):
$pathTo = "$BpathTo\User"
Write-Host -NoNewline "Setting ANDROID_SDK_HOME to:      $pathTo"
[Environment]::SetEnvironmentVariable("ANDROID_SDK_HOME", $pathTo, "Machine")
Write-Output "              ...Done"
Write-Host -NoNewline "Setting ANDROID_EMULATOR_HOME to: $pathTo"
[Environment]::SetEnvironmentVariable("ANDROID_EMULATOR_HOME", $pathTo, "Machine")
Write-Output "     ...Done"
Write-Host -NoNewline "Setting ANDROID_AVD_HOME to:      $pathTo"
[Environment]::SetEnvironmentVariable("ANDROID_AVD_HOME", $pathTo, "Machine")
Write-Output " ...Done"
#Create/Update ANDOID_HOME environmental variable:
### The Program data, usually found under "C:\Program Files (x86)\Android Studio\"
$pathTo = "$BpathTo\SDK"
Write-Host -NoNewline "Setting ANDROID_SDK_ROOT to:      $pathTo"
[Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", $pathTo, "Machine")
Write-Output "               ...Done"
Write-Host -NoNewline "Setting ANDROID_HOME to:          $pathTo"
[Environment]::SetEnvironmentVariable("ANDROID_HOME", $pathTo, "Machine")
Write-Output "               ...Done
Write-Output "Keep up to date on Android Studio's environmental variables:

#Update PATH environmental variable:
Write-Output "Updating PATH:"
$pathTo = "$BpathTo\SDK"
Write-Output "Adding: $new1"
Write-Output "Adding: $new2"
Write-Output "Adding: $new3"
Write-Output "Adding: $new4"
Write-Output ""
Write-Output "Done... Environment Setup Has Finished."
Write-Output ""

#Install Chocolatey and choco packages:
$InstallChoco = $False
##TODO:##if (Get-Command choco.exe -ErrorAction SilentlyContinue) {$InstallChoco = $true} #tests if choco.exe exists
If(Test-Path -Path "$env:ProgramData\Chocolatey") {} Else {$InstallChoco=$true} #tests if choco exists in $env:
if ($InstallChoco){ #Installs choco if not already installed
    Write-Output "Installing 'Chocolatey Installer'"
    iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
    Write-Output `n}
$Packages = 'ADB', 'NotepadPlusPlus' #<-- Add packages here
ForEach ($PackageName in $Packages){ #installs choco packages listed above, one by one.
    Write-Output "Attempting Chocolatey Install: $PackageName"
    choco install --force $PackageName -y 
    Write-Output `n}

#Launch the Studio:
$pathTo = "$BpathTo\android-studio\bin\studio64.exe"
Write-Output "Starting Process: ANDROID STUDIO (x64)"
Write-Output "Initiating @ $pathTo"
Start-Process $pathTo
Write-Output `n

#Startup the Emulator:
##TODO:##See above link regarding setting emulator variables.
##First, update the emulator's *.ini to match the current directory:
Write-Host -NoNewline "Updating Emulator: $avdPath..."
if (Test-Path $avdPath){Remove-Item $avdPath}
New-Item $avdPath | Out-Null
Clear-Content $avdPath
Set-Content $avdPath "avd.ini.encoding=UTF-8
Write-Output "Done"

##Second, Launch the emulator:
Write-Output "Launching: 'Nexus_x86' Emulator..."
$arg="-avd Nexus_x86"
$pathTo = "$Bpathto\localInstall\emulator\emulator.exe"
SDK\emulator\emulator.exe -avd Nexus_x86
Write-Output `n

#Wait for user response to close the window
Write-Host -NoNewLine "Script Finished. Press any key to close this window..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

In this picture, I detailed the steps mentioned above to cancel the setup wizard.

I'm looking to skip this step, and get straight to the Studio. Any help is appreciated.

Cancelling The Setup Wizard:

    • thanks. Looking through the files in my user folder (for me "E:AndroidUser.AndroidStudio3.3"), can't find a file that contains such a flag. Any idea where specifically to look, or what the flag might be called?
    • The AS configuration is stored in your user folder (in my case it's .AndroidStudioPreview3.5, which I believe includes the flag for whether or not the setup wizard has run. What if you keep that folder on the drive as well, and then copy it to the user folder using your script?

Further research - and I'm back to answer my own question.

Android Studio runs from the "\bin" folder. This is the folder where the actual studio executable is located. In that folder is a file called idea.properties which, among other things, points the IDE toward the user specific System and Config folders, usually located under C:\USERS\User.AndroidStudio3.x.

Add the following code to the script befor launching the Studio, to update that file with the current drive/directory for a truly portable - no setup - studio installation:

$BpathTo = (Get-Item -Path ".\").FullName
$pathTo = "$BpathTo\android-studio\bin\idea.properties"
Clear-Content $pathTo
Set-Content $pathTo $newCont

(The extra lines added are necessary for the smooth operation of the studio.)

  • 1
Reply Report