Home » Android » Android Studio: how to attach Android SDK sources?

Android Studio: how to attach Android SDK sources?

Posted by: admin March 11, 2020 Leave a comment

Questions:

How can I attach Android SDK sources to Android Studio?

When I open one of the Android classes, the “Sources not found” window with “Attach Sources” option doesn’t appear.

What is the other way to do this?

How to&Answers:

Open your sdk manager from toolbar menus and download the “Sources for Android SDK” for the API level defined in your build.gradle file like

compileSdkVersion 19 // compile with API level 19

Nothing else needs to be done.

Note : Sources for SDK is available only for API levels 14 and above.

UPDATE ( Based on stable release 3.2.1):

Google changes the approach of shipping the sources, so lets see what changed.

Go to the following location

Preferences -> Apperance & Behaviour -> System Settings -> Android SDK

Quite lazy to navigate type SDK in search and studio will help you to take to right place.

enter image description here

You can read the description, says mostly what to do.
So after clicking on “show package details” you will see whether sources are installed or not (as shown in below picture) if it is not installed do install and you are good.

enter image description here

Answer:

Android Studio 3.2.1 reporting in:
solved the issue by resetting SDK.

Preferences -> Appearance & Behavior -> System Settings -> Android SDK.

Click on Edit to the right of Android SDK location.
Next, Next, Finish to complete the wizard and voila!

Answer:

I’m unable to find the aforementioned gui options in v8.11 on osx however grep-fu tells me:

config is stored in ~/Library/Preferences/AndroidStudioBeta/options/jdk.table.xml

After editing this file (with Studio stopped) and restarting source mapping works fine for me.

diff --git a/options/jdk.table.xml b/options/jdk.table.xml
index 0112b91..33828b8 100644
--- a/options/jdk.table.xml
+++ b/options/jdk.table.xml
@@ -76,7 +76,7 @@
         </javadocPath>
         <sourcePath>
           <root type="composite">
-            <root type="simple" url="file:///Applications/Android Studio.app/sdk/sources/android-19" />
+            <root type="simple" url="file:///Users/tehdawgz/dev/android-sdk/sources/android-19" />
           </root>
         </sourcePath>
       </roots>

Answer:

For me on 2016/08/29 running android studio 2.1.3:

I had downloaded and was compiling against api 24 before the sources were released. I want to point at the source now that they’ve been released. Restarting Android Studio after downloading the sources in the SDK manager wasnt working.

I had to act like I was going to Edit the SDK location in the SDK Manager, when I did that, I could just click ‘next’ through the dialog and re-indexed the sdk stuff automatically.

button for edit SDK location
where to just click next through

Answer:

gdawg’s solution worked for me as well in Windows 10 and Android Studio 2.0. With the small modification that the jdk.table.xml file is located at

C:\Users\{USER_NAME}\.AndroidStudio2.0\config\options\jdk.table.xml

Answer:

Not sure why the accepted answer only seems to work with API level 19. I was able to attach SDK sources for API level 15 by explicitly providing the source path for the SDK. Here’s what I did:

  1. Make sure I’ve downloaded the desired SDK sources and setup my build.gradle with the desired API level.
  2. In the Project window on the left, select the External Libraries drop-down.
  3. Right click the menu item and select Open Library Settings.
  4. Click the Sourcepath tab and use the + icon at the bottom left to link to the desired SDK sources (should be in something/sdk/sources)

Answer:

In android studio 0.8.6(Beta) (OSX 10.9.4), it seems that you can view the android source code directly without attaching the Sources manually.

The prerequisite is you should download “Sources for Android SDK” in “SDK Manager” and restart “Android Studio”

Answer:

Just follow these steps: Settings –> Android SDK –> Launch Standalone SDK Manager –> download your needed SDK sources(in every Anroid Version’s Sources for Android SDK) –> restart your Android Studio. If above don’t help, make sure you have downloaded the required SDK sources, and reset the Android SDK Location to refresh. I hope it helps.

Answer:

I didn’t know what menu step 3 of sfridman’s answer was referring to. Another way I managed to get to the source I was interested in was after Android Studio had brought up the .class I wanted to dive into:

Breadcrumbs to .class file

I could then right click on that breadcrumb and choose “Jump to source”:

enter image description here

It seemed to find it automatically from doing that, probably because I had installed the source via the Android SDK manager as described elsewhere.

Answer:

First, check you have already load source.

then reset Android SDK Location at settings.

I solved my problem by above method.

Answer:

The only thing that worked for me was:

  • Open the Android SDK Manager (Tools -> Android -> SDK Manager ->
    Launch Standalone SDK Manager)
  • uninstall all the SDK Platform and Sources for Android SDK (from all API levels)
  • restart Android Studio

Upon restart Android Studio will pop a wizard because no SDK is installed: install the SDK Platform and sources for the currently used API level.

Answer:

In Android Studio 2.3.3 on Windows 7, I had the problem that the already downloaded source files für API-Level 26 in folder SDK\sources\android-26 were not recognized. Using “File | Invalidate Caches / Restart” solved the issue for me.

Answer:

For me downloading and refresh was not helping. I tried to choose source but still same issue. So I did Invalidate Cache/Restart. Now its working.

I tried to edit the jdk.table.xml file but there was no entry for android-26, it was only till android-25, so i decided not to edit that file.

Answer:

As for 09/08/2019 there are available such sources

sources;android-15
    Description:        Sources for Android 15
    Version:            2

sources;android-16
    Description:        Sources for Android 16
    Version:            2

sources;android-17
    Description:        Sources for Android 17
    Version:            1

sources;android-18
    Description:        Sources for Android 18
    Version:            1

sources;android-19
    Description:        Sources for Android 19
    Version:            2

sources;android-20
    Description:        Sources for Android 20
    Version:            1

sources;android-21
    Description:        Sources for Android 21
    Version:            1

sources;android-22
    Description:        Sources for Android 22
    Version:            1

sources;android-23
    Description:        Sources for Android 23
    Version:            1

sources;android-24
    Description:        Sources for Android 24
    Version:            1

sources;android-25
    Description:        Sources for Android 25
    Version:            1

sources;android-26
    Description:        Sources for Android 26
    Version:            1

sources;android-27
    Description:        Sources for Android 27
    Version:            1

sources;android-28
    Description:        Sources for Android 28
    Version:            1

You can list them by ./pathtoandroidsdk/tools/bin/sdkmanager --list --verbose --no_https

For example, install by ./pathtoandroidsdk/tools/bin/sdkmanager "sources;android-28"

There is no need in Android Studio for downloading

Setup instruction in Android Studio

In app build.gradle set correct version of sdk which will include the desired sources

android {
    compileSdkVersion 28
    ...

To apply changes – restart IDE