34

A new problem just popped up yesterday. When I hover over a method or press Ctrl-Q, I used to get documentation info for that particular method.

But now I just get (pressing Ctrl-Q on SharedPreferences.getLong()):

Following external urls were checked:
            http://developer.android.com/reference/android/content/SharedPreferences.html#getLong-java.lang.String-long-
            http://developer.android.com/reference/android/content/SharedPreferences.html#getLong(java.lang.String, long) 

    The documentation for this element is not found. Please add all the needed paths to API docs in Project Settings.
        android.content.SharedPreferences
        public abstract long getLong(String s, long l)

I googled a lot, but couldn't find an answer. Which paths do I need to add and where?

j3App
  • 1,510
  • 1
  • 17
  • 26

6 Answers6

32

So for me the solution in Android Studio 4.1.1 was that I forgot to download the sources for SDK 30.

  1. Go to Tools > SDK Manager
  2. Check Show Package Details
  3. See if Sources for Android 30 is checked
Cyn45
  • 321
  • 3
  • 2
30

Note: as of AS 3.6.2 (or, maybe, even earlier) this is irrelevant and does not answer the question.

Answer for older Android Studio versions:

You Must Download Documentation for Android SDK from SDK Manager

screenshot

Den Drobiazko
  • 1,077
  • 1
  • 13
  • 33
5ec20ab0
  • 742
  • 6
  • 15
5

In Android Studio 4.1.1, I solved the problem by installing the Android SDK platform for my compile build version. In my case, that was Android 10.0 (API Level 29).

  1. Open File > Settings to open the Settings window.
  2. Go to Appearance & Behavior > System Settings > Android SDK.
  3. Select your target build in the SDK Platforms tab (for example, Android 10.0).
  4. Click OK to install the SDK platform.

Once it is done installing, check whether the documentation popups are back.

P.S. The target build is the compileSdkVersion setting in the build.gradle file.

Baracus
  • 580
  • 7
  • 15
4

This is a solution that works for me on Android Studio 4.0. It's a bit hacky and relies on making Android Studio realize that it is missing the source files for the current SDK you are on. This is what I did:

Warning: it is hacky and might seem illogical but it worked!

Create a HashMap (for Kotlin users search the docs, you can probably follow) Map<String, String> testMap = new HashMap<>(); Then add any random thing to the Hashmap: testMap.put("test", "test");

Now the important part. Put your cursor on the put() method that you just call above, go to definition by holding ctrl + b or cmd+b for mac users. It should then ask you if you want to decompile the byte code and just click "decide later." When it opens up, you should see at the top, a sentence that says something like "Cannot find source for Android API: xx(depending on what version your compile sdk is set to in build.gradle(app))" there will also be an option to download the source or refresh(if you've already downloaded). Obviously download, it should then bring a popup called SDK Quick-fix and should download the source. After that is done, you can click refresh and after a few minutes (it'll take a while) you should have your docs restored!

Hope it works out!

Amani Arman
  • 71
  • 1
  • 4
  • Nice trick, unfortunately the only thing I found out using it is that the sources for API level 32 is still not published. – soger Apr 19 '22 at 14:34
4

I had a hard time (AGAIN) finding the "Show Package Details" check box, so I included a picture.

You need to download the sources for the SDK version you are targeting.

  1. Appearance & Behavior > System Setting > Android SDK (Or shift+shift "SDK manager")

  2. On the "SDK Platforms" tab, check the "Show Package Details" box in the lower right hand corner.

  3. Check the box for the Android version you are targeting, hit "OK" to download.

Android SDK Settings "Show Package Details" highlighted

Tor Brick
  • 61
  • 3
  • You can get there quickly via the `SDK Manager` button in the toolbar, or the `SDK Manager` command in the Tools menu, or tap the Shift key twice then type `SDK Manager` to search for that Action. **But** "Sources" are still unavailable for "Android API 32". How to link to its API docs? – Jerry101 Feb 27 '22 at 06:56
0

For all those using Android 4.1.1 or higher, I found this bug in API Level 30. Maybe it would be solved in the future.

Firstly make sure, you have installed the latest and stable Android SDK available. (Currently API Level 29).

For now, in build.gradle(app), I changed:

android {
  compileSdkVersion 30
  // other code

  defaultConfig {
    targetSdkVersion 30
    // other code
  }
}

to:

android {
  compileSdkVersion 29
  // other code

  defaultConfig {
    targetSdkVersion 29
    // other code
  }
}

The documentation will work now. Hope this works!

Jaineel Mamtora
  • 498
  • 4
  • 10