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.
- 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.
- 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.
- Click File —> Other Settings —> Default Project Structure in android studio to open the Project Structure dialog window.
- Then click the SDK Location item on the left side, then you can get the Android SDK location folder path on the right side.
- 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.
- 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.
- 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.
- You can also install a new version of the Android SDK source code if you can not debug the android SDK source code.
- 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)
- 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.
- 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 ).
- 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 the below steps.
- Open android studio configuration options folder like this C:\Users\Jerry\.AndroidStudio2.3\config\options.
- Open the jdk.table.xml file in the above options folder.
- You can change the sourcePath element’s value to your desire for each android SDK element.