How To Debug Android SDK Source Code In Android Studio

When you develop an android application with android studio, sometimes you may encounter strange errors. To resolve such an issue, the best way is to debug and step into android SDK source code to see how the code implements in detail. This article will tell you how to do that.

1. Get Project Target SDK Version In build.gradle File.

  1. First, you need to make sure that your compileSdkVersion and targetSdkVersion which is saved in the build.gradle file matches your SDK source code version.
  2. In the android studio left android Project panel, click Project Name —> app —> build.gradle file. In the right panel, you can see the compileSdkVersion and targetSdkVersion values.

2. Get The Current Installed Android SDK Version Folder.

  1. Click File —> Other Settings —> Default Project Structure in android studio to open the Project Structure dialog window.
  2. Then click the SDK Location item on the left side, then you can get the Android SDK location folder path on the right side.
  3. Open the above Android SDK location sources folder in file explorer, you can see a list of current android SDK source code folders such as android-25.
  4. If the Android SDK source code version does not equal to compileSdkVersion and targetSdkVersion value in build.gradle file, then change the compileSdkVersion and targetSdkVersion value in build.gradle file.
  5. After the SDK version value is changed, the android studio will prompt you to install the new version-related build tools. After download and install it, you will find you can debug and step into android SDK source code successfully.

3. Install New Version Android SDK Source Code.

  1. You can also install a new version of the Android SDK source code if you can not debug the android SDK source code.
  2. Click the android library class method in your source code then it will direct you to the Android SDK source file code. Because your installed SDK source code version does not match the compile and target SDK version. So android studio will prompt messages like below.

    Decompile .class file, bytecode version: 52.0(Java 8)                                       Choose Sources...
    Sources for 'Android API 26 Platform' not found.                       Download Refresh(if already downloaded)
  3. Click the Download link at the top right corner of the prompt message. It will show you a dialog that downloads the related SDK source code.
  4. When the download process is complete, click the Finish button, you can find the new version SDK source code folder under the “%ANDROID_HOME%\sources” folder ( for example  C:\Users\Jerry\AppData\Local\Android\sdk\sources ).
  5. Restart android studio, then you can debug android SDK source code now.

4. Edit Android SDK Source Code Folder Manually.

  1. If you want to change the SDK source folder manually, you can follow the below steps.
  2. Open android studio configuration options folder like this C:\Users\Jerry\.AndroidStudio2.3\config\options.
  3. Open the jdk.table.xml file in the above options folder.
  4. You can change the sourcePath element’s value to your desire for each android SDK element.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.