Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio steps into wrong sdk source

I've got the following build.gradle settings.

compileSdkVersion 21
buildToolsVersion '21.1.1'

defaultConfig {
    minSdkVersion 18
    targetSdkVersion 21
}

The problem is that when I step into Android SDK source on an KitKat device (19 on Genymotion or Device), it still insists on stepping into Android-21 source instead of 19.

Changing any of the above settings simply breaks the compilation of my app since I have v21 code. All 19 calls are protected properly and the code works on 19, just the source code linkup is incorrect.

Cheers in advance Stack Overflow brothers and sisters!

like image 997
John Twigg Avatar asked Feb 21 '15 00:02

John Twigg


People also ask

Can I change SDK version Android studio?

Select the tab Flavors on the right panel, click the defaultConfig item in the dialog center list area. Then you can select your desired android Min Sdk Version and Target Sdk Version from the related dropdown list on the right side. Click the OK button to save the selection.

What is targetSdkVersion in Android Studio?

android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level.

How to enable Android SDK in Android Studio?

Step 1: Opening Android Studio Settings. Navigate to the File > Settings option you will get to see below dialog screen. Inside that screen. Click on Appearance and Behavior option > System Settings options and then click on the Android SDK option to get to see the below screen.

How to update SDK path in Android Studio?

You can update your SDK path by clicking on the Edit option. After that select your SDK path, then click on Apply option, and then click on the OK option. Now sync your project with Gradle files to check that SDK is working fine.

How do I find the SDK location in Android Studio?

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.

What to do if Android SDK source code version is not equal?

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.


2 Answers

Android Studio 2.2 fixes it (mostly), and will jump to sources of API level that corresponds to the device that you're actually running on (as long as you have those sources installed). It was announced here.


Although the fix in Android Studio 2.2 works for public/standard builds, if the device is using a custom build (ie they made some changes to parts of the framework and assigned it a proprietary build id) then the 'fix' will not find the most closely matching source. The following technique is useful to get a version of the source that more closely matches the corresponding API level:

  1. Compile the application without any changes.
  2. Launch the application in Debug mode (and optionally break on breakpoint).
  3. Go to File > Project Structure, find your app module (or/and optionally, any other modules) and change the Compile Sdk Version to one that matches the device you're debugging on (i.e. 19).
  4. Step into the framework code - it should step into SDK 19 sources.

Warning: This causes Studio to sync and reevaluate your code and may cause problems. So changing this temporarily may get you the right source code, but you may have to change it back to build the next time. (as @Null Pointer points out) This is an imperfect, but useful technique.

like image 129
Alex Lipov Avatar answered Oct 24 '22 14:10

Alex Lipov


As was mentioned in another answer, it was fixed in Android Studio 2.2 (bug report).

However, it still wasn't working for me even in Android Studio 3.0 It started working only after I checked "Show alternative source switcher" in Settings.

screenshot

like image 10
igorz Avatar answered Oct 24 '22 13:10

igorz