How to attach the Kotlin library sources?

I seem to have lost the source attachment with the latest update (I can no longer go to a source inside the Kotlin libraries). When I click on the "Attach sources" hyperlink and I get presented with a dialog, which path should I put there? It's not quite clear to me from the folder structure of the github project...

Thanks.

It's easy: you need to put the path to root folder which contains sources. If this folder is under jar, there's no problem: you can expand jars as usual folders in this dialog.

If you lost sources of Kotlin runtime, try removing kotlin-runtime.jar and reinstalling it using editor warning bar. If this doesn’t help, maybe there is a bug in navigation to sources.   

Android Studio 1.4 beta 2 (also 1.3, and probably any other) Kotlin plugin 1235, kotlin version 1230

If i do as suggested, i get infinite Attaching… in toolbar
/uploads/kotlinlang/original/1X/23f9058bd87bc204eb82c22f0a6955ecbe4ea5d9.png

Also my library jar have jar with sources, and it’s not resolved either.

/uploads/kotlinlang/original/1X/8490830febe6fa951decb6487d9289e47affcc45.png

I can’t debug code in dependent libraries, its frustrating

Hi Dmitriy,

There is an issue in your tracker (https://youtrack.jetbrains.com/issue/KT-8592). We are investigating where the problem is.

Issue is only about Choose Sources dialog(basically an IDE problem?) But i also can't get sources in normal case, with dependency via gradle.

Could you attach your build.gradle file to the issue, please? How did you configure sources for your library? Is the library written in Kotlin?

Natalia, i found my problem:

build.gradle in kotlin library project has setting:

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

i got an empty sources jar

is it possible that on older versions of kotlin it works correctly? because i tested it before and it worked Oo
I assume that after m12 manipulations with possibility to place java and kotlin files in same folder it was broken.

now i changed it to:

task sourcetypepepe: Jar) {
    from sourceSets.main.allSources
}

and it works now.

However i can't fix android-library source attaching (aar)

for example i can’t see sources for http://search.maven.org/#artifactdetails%7Cio.reactivex%7Crxandroid%7C1.0.1%7Caar
and also for my own android libraries.

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

sources are generated and i can see them under .jar, but can't get it to work in AS

I fail to generate sources using your last hint above.
The sources.jar gets genrated, but it contains only empty directories and no kt files.

Is there some documentation somewhere on how one would go about creating a kotlin (android) library along with a sources .jar?

I also use my kotlin library in a java based project and I wonder - what should I do to document it, for the users to see

Hey dude, is there any walkaroud to attach kotlin sources code in android project right now?

2 Likes

A bit late to answer, but it could help other.
I have an Android library with both java and Kotlin.

You have to give both source files.

task androidSourcesJar(type: Jar) {
       archiveClassifier = 'sources'
       from (android.sourceSets.main.java.sourceFiles, android.sourceSets.main.kotlin.sourceFiles)
   }