androidandroid-studiointellij-ideamaven-publishmaven-repository

Published sources in maven local repository not visible in Android Studio IDE if proguard (R8) minification turned on


I want to publish some sources so that consumers of our closed-source library can see the documentation in their IDEs. I have this working so far:

def listOfPublicApiFiles = [
        '/com/example/app/MyClass.java',
        '/com/example/app/MyOtherClass.java',
]

task androidSourcesJar(type: Jar) {
    archiveClassifier.set('sources')
    include(listOfPublicApiFiles)
    includeEmptyDirs = false
    from android.sourceSets.main.java.srcDirs
}

publishing {
    publications {
        standardRelease(MavenPublication) {
            afterEvaluate {
                from components.standardRelease
                artifact androidSourcesJar
            }
            groupId = 'com.company'
            artifactId = "myartifact"
        }
    }
}

This works perfectly if minifyEnabled false is set, but as soon as I set minifyEnabled true, then no documentation at all appears in the IDE (by pressing F1, etc). Is this an IDE bug? The sources.jar is still there and appears to be linked properly. I don't see why it shouldn't work. I've tried making sure that these public API files are not minified at all by setting keep in proguard-rules, but it doesn't help, documentation in IDE is blank.

I'm using Android Studio Dolphin | 2021.3.1 Patch 1 Build #AI-213.7172.25.2113.9123335, built on September 30, 2022 Runtime version: 11.0.13+0-b1751.21-8125866 aarch64

but I have also tried on Electric Eel and Dolphin Android Studio.


Solution

  • After looking into this problem for about a week, I finally found a reasonably simple solution:

    Convert the files you want to publish documentation for to Kotlin. That way the documentation still is visible when minifyEnabled true is set, with the above publishing script.

    I tried everything else that I could think of, but I'm not sure which part of the toolchain is breaking when the classes are Java. I assume it's either Gradle or IntelliJ.