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!
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.
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.
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.
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.
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.
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.
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:
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).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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With