12

I'm trying to attach the android source code to my gradle project using Android Studio. The problem is that the SDK tab does not appear if you are using a gradle project and I can not attach the source code. I tried with version 0.4.3 and does not work.

Any idea or work arround?

EDIT: I've attach a capture with my project structure without sdk option.

enter image description here

Thank you,

flipper83
  • 819
  • 1
  • 9
  • 24

2 Answers2

17

The short explanation is that Android Studio has added some functionality to try to automatically manage IntelliJ SDKs; if you give it a JDK path and Android SDK path in Project Structure > Android SDK, it will automatically create a Java SDK and Android SDKs for each API level you have installed in your Android SDK. The problem is, if it creates an Android SDK for an API level that doesn't have the sources downloaded, if you go into SDK Manager later and download the source, it doesn't pick that up and update its SDK. I've filed https://code.google.com/p/android/issues/detail?id=65230 for this. In that bug I list two workarounds, which I'll explain here:

You can actually get at the SDKs panel you're looking for. We hide it if you have a Gradle-based project open since we want Gradle-based project users to not have to worry about it, but since we also support IntelliJ-style projects that use its internal builder, it's still possible to access it so those users will be able to make their projects work. You can get at this panel if you access Project Structure without a project open. To do so:

  • Close all open projects
  • From the Welcome to Android Studio screen, go to Configure > Project Defaults > Project Structure > SDKs
  • Choose the appropriate Android API SDK that you installed source for, and go to Sourcepath panel
  • Press the + button, and choose the source directory.

If you're having trouble following that, let me know and I can post screenshots.

Another approach would be to blow away all of Android Studio's auto-created SDKs and let it rebuild them. To do that

  • Exit Android Studio
  • Delete the jdk.table.xml file, which on MacOS will be in your home directory under Library/Preferences/AndroidStudioPreview
  • Relaunch Android Studio
  • Go into Project Structure (either from the Welcome screen or from a project), and choose the Android SDK tab
  • Make sure the Android SDK location and JDK location are correct.
Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • 7
    This doesn't work in Android Studio Beta 0.8.2. I'm unable to browse to API 20 source code from callstacks (it only lists source code up to API 19. It lists .class files for API 20, but that's not source code so it's useless). In the Welcome screen, the default project structure doesn't have an "SDKs" section with a + button. It only has a "SDK Location" section with 2 textboxes: one for Android SDK and one for the JDK. Both are set correctly. I found jdk.table.xml and deleted it and restarted, but no change. – foo64 Jul 25 '14 at 21:12
  • 1
    Things have changed slightly. The issue is still the same but the fix is even easier. File -> Invalid Caches/Restart -> Invalidate and Restart, Taken from http://stackoverflow.com/questions/23378610/android-studio-quick-documentation-always-fetching-documentation – McP Jan 20 '15 at 16:08
1

Check the compileSdkVersion in your build.gradle file and download the "Source for Android SDK" for respective API from Android SDK Manager.

SDK manager icon will be available on Android Studio tool bar.

Nothing else needs to be done.

Note : Source Code for Android SDK is only available for and after API 13 .

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • sorry, but this didn't work for me :S I've checked if I have well configure the sdk, and that's correct and I have donwloaded the source code and the sdk that I was using, in my case api 19. I have in platform folders 'android-19' and in sources folder 'android-19' too :S – flipper83 Jan 24 '14 at 13:43
  • Go to File > Project Structure > Android SDK and check whether it is pointing to right sdk. It is observed for some users that they were pointing to wrong sdk(which comes with studio) – Piyush Agarwal Jan 24 '14 at 13:46
  • nop, sorry, I checked before write the question, is pointing agains my sdk, :S I completely lost. – flipper83 Jan 24 '14 at 14:12
  • what does your mean by SDK tab doesn't appear.. everything is working like a charm in mine. Not getting what is issue. Try to sync your project with gradle once it should not give any error. – Piyush Agarwal Jan 24 '14 at 14:44
  • I've attached a image with the project structure. Yes I tried sync the gradle project, install 0.4.3 android studio version,close and open, I'm thinking on remove the .idea folder an reimport the project. – flipper83 Jan 24 '14 at 14:50
  • remove .imls files as well amd reimport. – Piyush Agarwal Jan 24 '14 at 15:00
  • yeah, it the best solution for all on AS 0.4.2 XD, I had a lot of problems adding aar files, only take the R class, I need reimport the project all time :S I will try along this weekend. – flipper83 Jan 24 '14 at 15:23