Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding it impossible to update android studio 2.0 to 2.1

I've been trying to update android studio to 2.1 from 2.0 and have run out of idea's. I'm getting a

java.lang.OutOfMemoryError: Java heap space

error. I've tried goggling to find solutions and have tried ones such as these with no joy:

StackOverFlow Answer

Tech-Docs from Google

Here's the full error I'm receiving:

Temp. directory: C:\Users\Aaron\AppData\Local\Temp\
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3236)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at com.intellij.updater.Utils.copyStream(Utils.java:165)
at ie.wombat.jbdiff.JBPatch.bspatch(JBPatch.java:83)
at com.intellij.updater.BaseUpdateAction.applyDiff(BaseUpdateAction.java:112)
at com.intellij.updater.UpdateAction.doApply(UpdateAction.java:44)
at com.intellij.updater.PatchAction.apply(PatchAction.java:184)
at com.intellij.updater.Patch$3.forEach(Patch.java:308)
at com.intellij.updater.Patch.forEach(Patch.java:360)
at com.intellij.updater.Patch.apply(Patch.java:303)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:84)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:75)
at com.intellij.updater.Runner.doInstall(Runner.java:280)
at com.intellij.updater.Runner.access$000(Runner.java:17)
at com.intellij.updater.Runner$1.execute(Runner.java:246)
at com.intellij.updater.SwingUpdaterUI$5.run(SwingUpdaterUI.java:191)
at java.lang.Thread.run(Thread.java:745)

I've created the .vmoptions file in the correct directory by going to Help > Edit Custom VM Options. The file created was named studio64.exe.vmoptions in case that's of any interest the contents of this file after I edited the one line is:

# custom Android Studio VM options

#
# *DO NOT* modify this file directly. If there is a value that you would like to    override,
# please add it to your user specific configuration file.
#
# See http://tools.android.com/tech-docs/configuration
#
-Xms256m
-Xmx2048m //Edited Line
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-da
-Djna.nosys=true
-Djna.boot.library.path=

-Djna.debug_load=true
-Djna.debug_load.jna=true
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
-Didea.paths.selector=AndroidStudio2.0
-Didea.platform.prefix=AndroidStudio

I had trouble updating from 1.5 to 2.0 before as well and had to do a clean install but that is very tedious for a 18MB patch file.

Finally here's what I think is a range of android related installation folders in what I think is a somewhat random spot. Don't know if that's my doing during the installation or android's:

Installation.

Edit:

This is the notification that I am presented with prior to updating. As you can see it's coming from the stable channel.

Updating.

There is plenty of spare memory available just in case I needed to point that out.

Cheer's for any help.

like image 264
COYG Avatar asked May 11 '16 04:05

COYG


2 Answers

I finally resolved the problem, just now.

After almost giving up I went back to the project I was working on and noticed that I was getting 18 instances of the same error when I was compiling an app that was in working order. This error was along the lines of _JAVA_OPTIONS_ -Xmx512m what was strange about this was in the file I created to set custom VM options this value was set at -Xmx2048m.

This led me to think that for some reason this VM option wasn't being recognised possibly because of a studio64.exe.vmoptions file in one of the previous android installation folders. I looked in these folders and did notice another file with this name! I deleted that re-ran the app but was still getting the same error.

This is when I then remembered I created an environment variable over a year ago when I was only starting out on Java and the book I was using to help get to grips with it recommend writing all the programs in a text editor to begin with AND to set environment variables through advanced options in windows. Well that environment variable was still present and lo and behold set at 512m:

1

(Path for anyone else who think they may have done this Control Panel » System » Advanced » Environment Variables)

Deleted this environment variable and to test the water before updating - restarted the app with no errors received this time. Stop running the app, attempted updating to 2.1.1 for the 45th and gladly the final time.

Apologies for not included the missing information in the question but as you can probably appreciate, it could easily slip anyone's mind.

like image 75
COYG Avatar answered Oct 09 '22 16:10

COYG


Based on the stack trace- you just need to customize VM options as below.

-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled 
-XX:+HeapDumpOnOutOfMemoryError

The location you have mentioned is the default location for the windows OS.

You will find Android Studio in these folders by default (unless you have customized it) based on the OS you are using:

in Windows should be in c:\user\yourname.AndroidStudio2.0

in Linux should be in /home/yourname/.AndroidStudio2.0

in Mac should be in ~/Library/Preferences/.AndroidStudio2.0

Also what you can do is-

a. fresh install Android Studio 2.0.

b. do export settings from the previous version-(which will create a .jar file for all the config)

c. import the settings in the newer version.

like image 39
Rajeev Dixit Avatar answered Oct 09 '22 14:10

Rajeev Dixit