18

I am unable find the source when after I downloaded the SDK. Has it been removed from public access?

Lii
  • 11,553
  • 8
  • 64
  • 88
zhyper
  • 183
  • 1
  • 1
  • 6
  • See also http://stackoverflow.com/questions/18298638/how-to-add-source-javadoc-for-android-support-v7 for Eclipse and http://stackoverflow.com/questions/27599536/how-to-see-source-for-android-support-v4-and-v7-in-android-studio – Paul Verest Dec 22 '14 at 09:05

5 Answers5

38

Some of the src folders on my copy of the samples, found at $SDK_DIR/extras/android/support/ seem to be empty. For example, v7/gridlayout/src/ is an empty folder, but most of my v4 folders have the source code supplied alongside the download from the SDK Manager, so I'm going to guess you and I are seeing the same issue.

However, you can always download the source directly from the source (no pun intended):

Doing a git clone https://android.googlesource.com/platform/frameworks/support/ to download the support library files direct from Google's repository seems to contain all of the source files.

Kasra Rahjerdi
  • 2,483
  • 26
  • 42
  • 1
    Do you have idea about how the give the Eclipse ADT access to the source code? When I try to set the source location of the libraries from Eclipse it tells me it `...does not allow modifications to source attachments`. – Lii Apr 16 '14 at 12:03
  • 3
    Thanks,but how to get the exact version of source code,such as "21.0.2"、"21.0.3"? I only can find the tags:"android-5.1.0_r1"... – cruelcage Mar 13 '15 at 06:41
  • The closed repository doesn't seem to have the same package structure as the class files on my classpath. That makes Android Studio unable to connect to the sources. On the classpath: `android.support.v7.widget.RecyclerView`In the cloned sources: `androidx.recyclerview.widget.RecyclerView`. – Lii May 03 '19 at 08:54
  • What if it is an `AndroidX`? – wonsuc Aug 15 '19 at 11:14
3

Those that are looking for sources per version, can find it locally (provided that you downloaded it previously) at:

$SDK_DIR/extras/android/m2repository/com/android/support/$libname/$version/$libname-$version-sources.jar

Jar file (as you probably know) is essentially a zip file - therefore you can simply extract its contents.

For example, support-v4 v23.1.1 located at:

$SDK_DIR/extras/android/m2repository/com/android/support/support-v4/23.1.1/support-v4-23.1.1-sources.jar
Alex Lipov
  • 13,503
  • 5
  • 64
  • 87
0

Using Android Studio to read support library source is a more convenient way.Please follow these steps:

  • Add dependency to support library in build.gradle. For example, compile 'com.android.support:appcompat-v7:23.1.0' in Android Studio project's build.gradle.
  • Sync or build your project.
  • Add a reference to support library class from your code file and then ctrl+right click.This will lead you to the source code.
  • There is a "Scrool from Source" toolbar button in project view.Click it and you will be navigated to the source code tree in project view.For example, at $PROJ/build/intermediates/exploded-aar/com.android.support/design/23.1.0/jars
zombielei
  • 163
  • 1
  • 8
0

I found my sources in the following directory:

<SDK_DIR>/sources/android-26
<SDK_DIR>/sources/android-28

Setting those directories in Android Studio allowed it to attach to the sources.

Sources for some components are only available in some of the version specific sub-directories.

I'm on Windows 10, using Android Studio 3.4.

Lii
  • 11,553
  • 8
  • 64
  • 88
-3

go to Android SDK manager then> go to extras>select Android Support Libraries >check on that and install it

Junaid Akram
  • 111
  • 1
  • 2