Monday, 9 March 2015

How to Solve : Android SDK Manager Won't Start / Open in Eclipse



So i boot up eclipse one day and the Android SDK won't open up and instead i am greeted by this error message in the console (see below) and so googled the error, checked out forums, spent (almost) the whole night trying to solve this, finally did solve it but also saw that a lot of developers were facing the same problem and there was no proper universal solution since most of the fixes given on the internet were unfortunately not working for the many, including me. So now that I finally successfully solved it, here's a proper guide to troubleshooting this seemingly prevalent problem so that no other developer has to waste any more of his/her productive time on this and can quickly get on with their business.


Courtesy: JD Hancock, Flickr



NOTE : During the duration of this tutorial, please open every file is mentioned in the guide 'as an Administrator'. 

NOTE : If one solution doesn't work for you, just keep on moving to the next solution until you get it working. If you do manage to fix it, please comment down below saying the same and mentioning the solution number that worked for you. Conversely, if none of the solutions work for you, please mention the error you are getting in the console.


This is what the error looked like for me






ACCESSING ANDROID SDK:
For the duration of this guide, we will be accessing Android SDK through two ways as explained below. Please keep them in mind since throughout the guide we will be referring to these methods.

1. Opening it up from Eclipse IDE itself by going to Window > Android SDK Manager.



2. The Second way is through android.bat file  present in the downloaded Android SDK folder itself.

  • Open the [android-sdk-folder]/tools folder where the 'android-sdk-folder' for me is 'C:\android-sdk-windows\' so the path becomes: 'C:\android-sdk-windows\tools'. In that particular folder, there is an 'android.bat' file as shown in the screenshot below. Double clicking it opens Android SDK as well.







SOLUTION 1:

The first and foremost thing that you should try if you haven't already is to try to open Android SDK from Eclipse and android.bat (as explained above) by opening these respective files 'as an Administrator'. As simple as it may be, it has worked out for many and hence definitely worth a try.




SOLUTION 2: 

The second most common solution to this problem is deleting the '.android' folder and then to try to open the Android SDK folder by both the methods described above in 'Accessing Android SDK' section. How?

  • Go to My Computer > Users > [your-username]. Where the username for my case would be 'com' so the path becomes 'C:\Users\com'
  • Find the '.android' folder which is usually on the top. Copy and make a backup of it in somewhere else and delete this one.
  • Once deleted, fire up Android SDK from Eclipse or android.bat file (as explained above).







SOLUTION 3: 

  • Go to android.bat file from the [android-sdk-folder]/tools folder where the android-sdk-folder for me is 'C:\android-sdk-windows\' so the path becomes: 'C:\android-sdk-windows\tools'. In that particular folder, there is an 'android.bat' file as shown in the screenshot below. 




  • Right-click on the 'android.bat' file and select 'Edit' to open the file contents in notepad.
  • Press Ctrl+F to find and search "set java_exe".





  • Now edit the line  “set java_exe=” line to include the path of JDK java executable file (java.exe) by setting the line as java_exe=C:\Program Files\Java\jdk1.7.0_75\bin\java.exe where “C:\Program Files\Java\jdk1.7.0_75\bin\java.exe" is the path to the java executable file for the installed JDK. So set it according to your directory path. 
  •  If setting the JDK path doesn't work, enclose the path in double quotes ("") and try again. If it still doesn't work, try to set the path to JRE, java.exe file and try again with and without the enclosing double quotes. The line in each of those cases would look like:
  java_exe="C:\Program Files\Java\jdk1.7.0_75\bin\java.exe"
java_exe=C:\Program Files\Java\jre1.8.0_40\bin\java.exe
 java_exe="C:\Program Files\Java\jre1.8.0_40\bin\java.exe"



  • Save the file and hit close. Test it out in Eclipse by going to Window > Android SDK Manager or by opening the 'android.bat' file as explained above in the accessing SDK section.
  • If it still doesn't work, you should be getting an error similar to this. Fret not, move on to the next solution.







SOLUTION 4:

  • First of all remove all pre-existing versions of java (JDK and JRE) from your system by uninstalling them from the remove programs section in control panel.
  • Download JDK 1.7.x.x version from the Oracle Java download website. It's very important to download specifically the version 1.7.x.x of JDK because as it turns out that Android SDK does not support JDK 8 as of now. Download either the 32bit or 64bit depending on whether your system is 32 bit or 64bit. To find out which bit version of windows you are running, refer to this guide





  • Now we need to set the path to the new JDK and JRE in the environment variables. So go to Start > Right-click on My Computer > Properties > Advanced System Settings > Environment Variables
  • Find the PATH variable under system variables tab and press edit. Now add the path directory to the bin folder of JDK and JRE at the end like this: C:\Program Files\Java\jre1.8.0_40\bin;C:\Program Files\Java\jdk1.7.0_75\bin; (Don't forget to keep the semicolon at the end)


  • Now once that's done, click 'New' to create a new variable. Set the Variable name to 'JAVA_HOME' and the variable value to the path to the bin folder of JDK which would be C:\Program Files\Java\jdk1.7.0_75\bin for my case.




  • Now perform the exact same steps as mentioned in SOLUTION 2 i.e going to My Computer > Users > [your-username] directory and deleting the '.android' folder after making a backup of the same folder elsewhere.
  • Now as explained in the 'Accessing Android SDK' section above, go to the [sdk-tools]\tools directory which for me is C:\android-sdk-windows\tools. 
  • Find the 'android.bat' file, Right-click on it and select 'Edit' to open the file contents in notepad. Now make the following changes:

ORIGINAL
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF

MODIFIED
set java_exe=C:\Program Files\Java\jdk1.7.0_75\bin\java.exe
rem call lib\find_java.bat
rem if not defined java_exe goto :EOF

NOTE : Copy and paste your own java.exe path directory as explained previously.



ORIGINAL
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a

MODIFIED
rem for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a
set swt_path=lib\x86_64

NOTE : If your android sdk is 64bit then mention set swt_path=lib\x86_64 otherwise if it is 32bit then keep it as set swt_path=lib\x86


  • Hit Save and close the file. Now go to Eclipse > Windows > Android SDK. The SDK manager should fire up in a few seconds. Enjoy!




If the guide helped you troubleshoot the issue, please drop a comment below saying the same and mentioning the solution number that worked for you. Conversely, if none of the solutions work for you, please mention the error you are getting in the console. Also if you found the guide to be little confusing, please do let me know as to in which part did you had to struggle.  Thanks!


-Kaushal Kapoor