How To Debug Android SDK Source Code In Android Studio

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

1. Get project target sdk version in build.gradle file.

First you need to make sure that your compileSdkVersion and targetSdkVersion which is saved in build.gradle file match your sdk source code version.

In left android project panel, click Project Name —> app —> build.gradle. In right panel, you can see the compileSdkVersion and targetSdkVersion.

android project build.gradle file

2. Get current installed android sdk version folder.

Click File —> Other Settings —> Default Project Structure in android studio. You can get the android sdk location folder.

android sdk location folder in android studio

Open sources folder in above folder in file explorer, you can see a list of current android sdk source code folders.

android sdk source code folder

If the android sdk source code version do not equal to compileSdkVersion and targetSdkVersion value in build.gradle file, then change the compileSdkVersion and targetSdkVersion value in build.gradle file.

After sdk version value changed, android studio will prompt you to install version related build tools as below. After download and install it, you will find you can debug and step into android sdk source code successfully.

install android buid tool for new version

3. Install new version android sdk source code.

You can also install new version sdk source code if you can not debug android sdk source code.

Click the android lib class method in your source code then it will direct you to below code. Because your installed sdk source code version do not match compile and target sdk version. So android studio will prompt messages like below.

download android sdk source code

Click the Download link at the top right corner of prompt message. It will show you a dialog which download the related sdk source code.

download new android sdk version

When the download process complete, click Finish button, you can find the new version sdk source code folder under “%ANDROID_HOME%\sources” folder ( C:\Users\Jerry\AppData\Local\Android\sdk\sources ).

Restart android studio, then you can debug android sdk source code now.

4. Edit android sdk source code folder manually.

If you want to change the sdk source folder manually, you can follow below steps.

  1. Open android studio configuration options folder like below.  C:\Users\Jerry\.AndroidStudio2.3\config\options
  2. Open jdk.table.xml file in options folder.
  3. You can change sourcePath element’s value to you desired for each android sdk element.
4 5 votes
Article Rating
Notify of

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

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x