A repository of bitesize articles, tips & tricks
(in both English and French) curated by Mirego’s team.

How to enable the alternative source switcher in Android Studio

It happens frequently in Android Studio projects to have multiple versions of the same library, mostly because of the variety of transitive Gradle dependencies an application relies on. Sometimes, while debugging an app using breakpoints, Android Studio will resolve an older version of a library than the latest one being run on the device. In this case, the source code probably won't match and the debugging process will be way more difficult.

Luckily there is an option that we can enable in the Android Studio settings that can fix this issue. If you go to Preferences -> Build, Execution, Deployment -> Debugger -> Java, there is a checkbox called Show alternative source switcher.

Show alternative source switcher checkbox

When enabled, a banner will appear in the top of the source file tab while the execution is suspended on a breakpoint, offering the possibility to select the most recent file version. Take note that this also works with the Android API source code!

Source switcher banner

From now on, having this option enabled will surely encourage you to break into Android's base classes when encountering issues and help you having a better understanding on how everything works under the hood!