2

I created a small Android library for personal use and distribute it over Jitpack. If I add it to my projects via Gradle and go to inspect the source code of an imported method, I can only see a decompiled .class file. How can I provide the consumers of my library the source code?

sunilson
  • 1,449
  • 15
  • 31

2 Answers2

0

Then do not add it as a Gradle dependency. Instead add it as a module.

File -> New -> New Module

Add your source code here.

Add this module path in app level Gradle dependency

For example if your module name is MyModule

implementation project(':MyModule')

That's it. You are good to go.

Mustaqode
  • 453
  • 1
  • 4
  • 14
  • Thats not what I need, I want to have it in a remote repository to easily add it to any project and updating all usages at once instead of adjusting the source code in every project I used my library – sunilson Jul 30 '20 at 05:52
0

So in the end I solved it by using a JAR like the comments of Henry and Morrison suggested:

In my libraries build.gradle:

apply plugin: 'maven-publish'

task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "sources"
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                // Applies the component for the release build variant.
                from components.release

                groupId = 'REPLACE WITH YOUR JITPACK ID (com.github.xxx)'
                version = 'x.x'

                // Adds javadocs and sources as separate jars.
                artifact sourceJar
            }
        }
    }
}
sunilson
  • 1,449
  • 15
  • 31