13

I'm publishing libraries to an internal Sonatype Nexus repository.

Android Studio has a feature that automatically finds the correct source for a library that is referenced through gradle. I publish the sources for our aar as a separate jar to the nexus. But Android Studio is not picking them up.

How do I have to publish the sources to make them available in Android Studio?

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
Janusz
  • 187,060
  • 113
  • 301
  • 369

2 Answers2

3

It's not possible at the moment.

Xavier Ducrohet
  • 28,383
  • 5
  • 88
  • 64
  • 1
    Libraries like Retrofit are making there source code available through MavenCentral. Is this a specific feature of Maven Central? – Janusz Mar 10 '14 at 13:18
  • It's a limitation of Gradle not downloading the source artifacts from a repository when building (because it's not needed when building). We need to get a way to make it download it and expose it through the model sent to the IDE. – Xavier Ducrohet Mar 10 '14 at 17:33
  • 1
    But if I go to a class from for example OkHttp Android Studio shows a button search for source. For most open source libs on Maven Central the source is found and displayed perfectly after clicking this Button. But for our own Repo it is not working. – Janusz Mar 11 '14 at 08:10
  • 1
    FYI retoryfit and okhttp are packed as jar not aar – worawee.s Aug 06 '14 at 09:06
  • Is this still not possible? – lostintranslation Dec 02 '14 at 17:07
  • 4
    @XavierDucrohet I could instruct Gradle to download the sources of my dependencies (like this https://gist.github.com/stefanhoth/37f86c8e41d648cbd2c8 )but classes from AAR files still can't find the sources. Any chance you will close the gap? – Stefan Hoth Jan 13 '15 at 10:30
  • Two years later and still no solution? I guess documenting stuff is not important on Android. – Nilzor Oct 31 '17 at 11:16
  • @XavierDucrohet As the accepted answer, please consider revising your answer to include more detail on matters such as discussions relating to this issue. – Chris Watts Nov 27 '18 at 19:28
3

I have wrote a gradle plugin for this function. Hope it will help you.

----- edit ------

How to publish Android .aar sources?

android {

    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
    }

    artifacts {
        archives sourcesJar
    }

    uploadArchives {
        repositories {
            mavenDeployer {
                ...
            }
        }
    }
}
Real.Xu
  • 209
  • 2
  • 5
  • Yes, this plugin is wrote for gradle 2.+. you can modify the plugin yourself if you need it. just a little change. – Real.Xu Dec 20 '14 at 13:35
  • 1
    So from my understanding your plugin helps downloading sources for dependencies, but the question here is "How to publish Android..". Can you answer that as well? When knowing that your plugin could be used to read them locally (as well) perhaps? – riper Feb 05 '15 at 10:33
  • 3
    I don't think the problem is unpublished sources, it's that Android Studio doesn't know where to look for them for AARs. We publish sources for all internal AARs, but AS still can't find them. – mxk Jul 14 '15 at 09:53