Android Studio: how to attach Android SDK sources?
AndroidAndroid StudioAndroid Problem Overview
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?
Android Solutions
Solution 1 - Android
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!
Solution 2 - Android
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.
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.
Solution 3 - Android
I'm unable to find the aforementioned gui options in v8.11 on osx however [grep-fu][1] 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>
[1]: https://github.com/ggreer/the_silver_searcher "grep-fu"
Solution 4 - Android
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.
Solution 5 - Android
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
Solution 6 - Android
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:
- Make sure I've downloaded the desired SDK sources and setup my build.gradle with the desired API level.
- In the Project window on the left, select the External Libraries drop-down.
- Right click the
menu item and select Open Library Settings. - 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)
Solution 7 - Android
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"
Solution 8 - Android
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.
Solution 9 - Android
Sharing, since it took me a while to realize: at the moment (August 2020) API level 30 does not have available sources (no such option in the SDK manager). I changed my application to target API level 29 (instead of 30), and made sure to download the sources for version 29 and it worked.
Make sure that "Show Package Details" is turned on to see if sources are available for the SDK version that you are targeting.
Also, it's now possible to use "Tools -> SDK Manager" instead of "File -> Settings -> etc...".
Solution 10 - Android
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:
I could then right click on that breadcrumb and choose "Jump to source":
It seemed to find it automatically from doing that, probably because I had installed the source via the Android SDK manager as described elsewhere.
Solution 11 - Android
First, check you have already load source.
then reset Android SDK Location at settings
.
I solved my problem by above method.
Solution 12 - Android
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.
Solution 13 - Android
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.
Solution 14 - Android
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.
Solution 15 - Android
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
Solution 16 - Android
I just met a similar issue when I need to download the platform android 28 via command line, I saw the answer to run command ./pathtoandroidsdk/tools/bin/sdkmanager "sources;android-28"
.
But in fact, from developer.android.com, it shows an example as sdkmanager "platform-tools" "platforms;android-28"
, so I guess it should be ./pathToAndroidSdk/tools/bin/sdkmanager "platforms;android-28"
.