Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

Android studio shows sources from API of compileSdkVersion when debugging on device with older API

I am debugging with Android Studio (A.S) 1.0.2 with compileSdkVersion 21 set up in build.gradle. When using an emulator with API 21 everything works fine. The problem occurs when debugging on a device having API 19. Each line in the call stack (tagged as 'Frames' in A.S) correctly shows the function name, source file and line number that matches API 19. However, when I click on one of the lines that corresponds with one of the framework sources (e.g. Activity.java), A.S incorrectly opens up and displays the API 21 version of the file rather than the API 19 version.

In my android sdk folder I have both ./sources/android-19 and ./sources/android-21

Any idea why A.S displays the wrong version of the file?

Things I tried (in order):

  • Resetting Android Studio (by removing ~/.AndroidStudio*)
  • Update Android Studio to latest version
  • Running on emulator with API 21 - A.S shows the correct version (21) of the files.
  • Changing compileSdkVersion to 19 and running on API 19 device - A.S shows the correct line numbers in call stack and opens the correct version (API 19) of the files in the correct line.
  • Changing compileSdkVersion to 19 and running on API 21 emulator - A.S shows, in the call stack, the line numbers corresponding to API 21 (which seems to me as the correct behavior), however, when clicking on it, A.S mistakenly opens up the API 19 version of the file rather than the API 21 version.

To summarize, when clicking on a line in the call stack A.S opens up the version of the file represented by compileSdkVersion and not the one used by the device/emulator during the debug session.

question from:https://stackoverflow.com/questions/27671859/android-studio-shows-sources-from-api-of-compilesdkversion-when-debugging-on-dev

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answered with working solution here:

https://stackoverflow.com/a/32236703/1267536

Full content:

I use appcompat support library quite a lot. Changing the compileSdkVersion only results in massive compile errors. If you are using appcompat-21, you must compile against api 21 or you will get compile errors.

This works fine if you are debugging against version 21. But when you are debugging on Jelly Bean (API 17), your debugger keeps dropping you to the API 21 source. Very annoying and hard to debug.

The solution I've ended up using is very hacky but works! Let's say you are trying to debug against API 17. Do the following:

  1. mv $ANDROID_HOME/sources/android-21 $ANDROID_HOME/sources/android-21-orig
  2. cp $ANDROID_HOME/sources/android-17 $ANDROID_HOME/sources/android-21
  3. restart android studio so it will pick up the correct paths.
  4. Debug

Just don't forget to put all the directories back after you're done.

Here's an android studio bug report about this issue: https://code.google.com/p/android/issues/detail?id=183976


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...