24

I have this grade file:

//ext.support_library_version = '24.0.0'

    android {
        compileSdkVersion 24
        buildToolsVersion '24.0.0'

        defaultConfig {
            applicationId "---"
            minSdkVersion 21
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
        }
    ...
    }

But then when i try to open any android related class, it says i haven't got sources for api24, even tho the buildToolsVersion '24.0.0' is installed. Any idea why?

laalto
  • 150,114
  • 66
  • 286
  • 303
johnny_crq
  • 4,291
  • 5
  • 39
  • 64
  • As long as you have `compileSdkVersion 24` you have to use support libs `24.x.x`. Same for 23. If you want to see some sources, download the API 23 sources via SDK manager and open them in your favorite text editor. `buildToolsVersion` has nothing to do with this, set it to latest available. – Eugen Pechanec Aug 17 '16 at 11:35
  • If you're still having the same problem, there is a solution here: [Sources for Android API 23 Platfrom not found (Android Studio 2.0)](http://stackoverflow.com/a/37283886/3675525) – Cifus Aug 25 '16 at 06:42

3 Answers3

32

Sources for Android N are not yet published and not available for installation in the SDK manager. When the source package becomes available, you need to install it separately, as with any previous SDK version.


Update 2016-08-24: The Android API 24 sources are now available in the SDK manager.

After downloading you might need this trick to refresh the SDK installation.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
  • hm. i just want to use the latest support-library library but then i need api24. is there any workaround for this? – johnny_crq Jun 16 '16 at 11:51
  • 2
    Only way to work around this is to use (cmd+o) and type the class name you are trying to see. At that point you can choose between the api 24 (decompiled) and the jdk version(sources). On the JDK version you can at least see some java doc and an implementation. What you see might not be the actual implementation that runs on device but should get you what you need. – TrevJonez Jun 17 '16 at 15:01
  • I suspect access to the doc comments is the only reason for this concern, so +1 to TrevJonez for providing the practical solution; cmd+o (Windows: ctrl+n) with "include non-project files" checked exposes the source from 23(or whatever). – anthropic android Jul 07 '16 at 21:33
  • 1
    as a workaround I had to change to SDK 23 to see the source code :( – Juan Saravia Jul 22 '16 at 20:57
  • @anthropicandroid for me, using the `include non-project files` does NOT expose SDK 23 sources :( – Henrique de Sousa Aug 09 '16 at 14:46
  • ya, the moment I got to a fresh install of android studio--i.e. only latest SDK installed--I noticed this stopped working. I believe that installing a lower version would get the files over there, but that's low on my priority list right now =\ – anthropic android Aug 24 '16 at 02:58
  • @laalto Even after installing the sources and restarting Android Studio, it is telling me "Sources not found". Any idea why? I checked `$ANDROID_HOME/sources`, and as expected it contains `android-24` with all the .java files. – friederbluemle Aug 25 '16 at 11:15
  • 1
    @friederbluemle: Yes I had the same issue and refreshing the SDK like in this answer helped: http://stackoverflow.com/a/36903786/101361 – laalto Aug 25 '16 at 11:41
  • @laalto: Perfect, that worked! Weird that neither "Refresh" nor "Download" in the quick tip that appeared didn't do anything. Thanks! – friederbluemle Aug 25 '16 at 11:52
  • @igor-ganapolsky unless I'm misunderstanding your post, this solution exactly as updated--but for 25--should not work for that, since you'd be installing the latest API version, which won't ever have the sources you want; Juancho's workaround and TrevJones' both rely on installing and using the previous version in some way, one directly and the other by including non-project files – anthropic android Oct 28 '16 at 08:11
1

I had the same problem with API 25 and Android Studio 2.2

Try the following:

  1. Close Android Studio.

  2. Open ~/Library/Preferences/AndroidStudio2.2/options/jdk.table.xml or C:\Users{USER_NAME}.AndroidStudio2.2\config\options\jdk.table.xml

Note the Android Studio version in the pach.

  1. Locate <sourcePath> for Android API 24 Platform and for previous one. You can look that <sourcePath> for problem API hasn't second <root> element with url.

  2. Investigate path of sources, check that sources was really installed.

  3. Copy <root> from another <sourcePath> and set correct url. It will be similar to

    <sourcePath>
      <root type="composite">
        <root type="simple" url="file://$USER_HOME$/Library/Android/sdk/sources/android-24" />
      </root>
    </sourcePath>
    
  4. Save the file and start Android Studio

https://stackoverflow.com/a/36825435/1263771

Community
  • 1
  • 1
tse
  • 5,769
  • 6
  • 38
  • 58
0

To get the newest Android API's (SDK Platform)

Make sure you update the Android SDK Tools to the latest version in the Android SDK Manager first.

TouchBoarder
  • 6,422
  • 2
  • 52
  • 60