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.
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.
Open sources folder in above folder in file explorer, you can see a list of current android sdk source code folders.
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.
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.
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.
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.
- Open android studio configuration options folder like below. C:\Users\Jerry\.AndroidStudio2.3\config\options
- Open jdk.table.xml file in options folder.
- You can change sourcePath element’s value to you desired for each android sdk element.