60

I have already checked this post: How to download dependency sources for Gradle project in IDEA?

But it didn't work for me. Maybe it is because they are referring to IntelliJ Idea, and I am having the issue with Android Studio.

I have tried adding

apply plugin: 'idea'
idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

Both to root's build.gradle file (I am in a multiproject setup) or to the application's build.gradle file.

My application's gradle file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}

repositories {
    mavenCentral()
}
dependencies {
    compile files('libs/android-support-v4.jar')
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.8.4'
}
android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

Then, in Android Studio when I click on any method from the universalimageloader library, I get to a screen saying that there are no sources attached. If I click attach sources it shows: enter image description here

As you can see, only the lib's jar was downloaded to gradle cache. No *-sources.jar or *-javadoc.jar were downloaded. I have cleaned project, removed .gradle folder to force it to download again from maven. No luck.

I double checked that universal image loaded has sources and javadoc available in maven, so that is not the problem.

Thanks!

Community
  • 1
  • 1
Monitus
  • 846
  • 1
  • 6
  • 12
  • I am running Android Studio 0.1.9 (latest to date) and gradle plugin 0.4.2 – Monitus Jul 02 '13 at 13:21
  • Seems to work now with a simple import project. I have version 0.2.6 which includes gradle version 1.7. – stigkj Aug 27 '13 at 19:47
  • @stigkj are you talking about android sources or any 3rd party library? Previously I could at least use project settings to import sources. In latest versions jar dependencies dialog is removed and I can't add it anyhow. Any ideas? – mente Nov 04 '13 at 15:47
  • 5
    So, a year later, have Google done anything to address this issue yet? I don't find any questions younger than about a year regarding this topic, so either it's been fixed or it's a sore subject nobody wants to discuss. – MrPlow Oct 13 '14 at 14:20
  • I do not have a solution for the problem, but a way to get a solution faster. ;) There is already an entry in googles issue tracker about it: [https://code.google.com/p/android/issues/detail?id=77425](https://code.google.com/p/android/issues/detail?id=77425) star it and we will get a solution soon hopefully! – andreas Mar 13 '15 at 11:42
  • 1
    @MrPlow Fix of this issue is going into the AS 1.4 release. See [here](https://code.google.com/p/android/issues/detail?id=59220). – naXa stands with Ukraine Apr 09 '15 at 06:56

7 Answers7

10

For Maven sources and docs the only thing I have found is to change the default settings.

File -> Other Settings -> Default Settings... -> Maven -> Importing

Checking the boxes to download Sources and Documentation settings thumb

Victor Häggqvist
  • 4,484
  • 3
  • 27
  • 35
  • Finally a clean solution, thank you! For non-maven libraries a possibility is to use the local maven repository and put the needed jar files with javadoc there. – Marc Demierre Jul 07 '15 at 16:53
  • 21
    There is no "Maven" in my android studio in Project settings or Preferences, in Mac, AS 2.3.3 – Computer's Guy Aug 29 '17 at 12:38
5

As we can see the answer from Xavier Ducrohet (Android SDK Tech Lead Google Inc.), as of July 26, 2013:

I don't think Gradle handles this at this point. I've talked to the devs and they are aware of it. We're looking at adding a hook in Gradle so that we can do it when the tooling API queries the model.

JJD
  • 50,076
  • 60
  • 203
  • 339
Abi-
  • 301
  • 1
  • 3
  • 8
3

Currently Android Studio imports libraries with sources. As for java docs press F1.

Old answer:

As we are talking about early preview, simplest fix wins.

For now is just manually add them to the project in Project Structure dialog. Things are even worse as now Android Studio will strip module files (iml) from all dependencies which are not related to native Android Gradle configurations and tasks e.g. module has robolectric dependency and extra task and config localTest is added in build.gradle. After you open Android Studio it will remove dependency, you need to add it again.

For time being I am keeping iml files and .idea folder in my git. After launch

git checkout myproject/myproject.iml
robotoaster
  • 3,082
  • 1
  • 24
  • 23
3

Try this plugin on github. It works for me.

Update: The GitHub repo's README.md now says:

This plugin in deprecated. AndroidStudio 1.4 has this support built in.

Flimm
  • 136,138
  • 45
  • 251
  • 267
misaka-10032
  • 179
  • 1
  • 4
  • 14
1

Unfortunately I cannot comment with my score, so:

Although this isn't an answer, if you use the 'eclipse' plugin in Gradle, you can run

gradle eclipseClasspath

And it will download all the sources and, I believe, Javadoc and create a .classpath with links to their locations.

Then, at least, you will have the sources and javadoc to reference, which I assume you can then reference in IntelliJ.

mmm111mmm
  • 3,607
  • 4
  • 27
  • 44
  • Tried this workaround, but it didn't really work. (`.classpath` was created but with no paths.) – Jonik Dec 07 '13 at 21:35
1

As in 2021, I download a third party library which has sources available but Android Studio doesn't get them, neither show the docs.

I follow these steps to get and see the sources with docs on my Android Studio:

  1. Download the source package library-sources.jar manually
  2. Open a class using some class from the library and press F1 on a method to get the doc.
  3. Once decompiled source code is shown, click on "Choose Source" from the top right.
  4. Use the dialog to select the file downloaded in step 1.
  5. Close the decompiled source. Press F1 again on a library's method.
RobertoAllende
  • 8,744
  • 4
  • 30
  • 49
0

For me the issue was due to Build Variants was set to release, so gradle tried to find aar for corresponding dependency. Switching Active Build Variant to debug solved the issue and Android studio downloaded all source dependencies itself.

View | Tool Windows | Build Variants | Active Build Variant

uptoyou
  • 1,427
  • 19
  • 24