2

I have made a library with some interfaces (HybridMediaPlayer on github). When I import it from gradle in new project and use those interfaces I get changed parameter names such as:

player.setOnPositionDiscontinuityListener(new ExoMediaPlayer.OnPositionDiscontinuityListener() {
     @Override
     public void onPositionDiscontinuity(int i, int i1) {

     }
});

Where the "i" is "reason" and "i1" is "currentWindowIndex". Why it is changed in other project and how to fix that? Proguard is disabled.

Sagar
  • 23,903
  • 4
  • 62
  • 62
Mateusz Kaflowski
  • 2,221
  • 1
  • 29
  • 35

3 Answers3

2

I think this is because on the Maven repo only a Android Archive Library (AAR) exists and no source jar. The AAR only contains the compiled classes and in compiled classes the full variable name is not known anymore. So when your IDE implements the method it doesn't know the names anymore so it defaults to standard naming based on argument types (hence the i for integer).

If you want the correct variable names you should publish a source jar of your project as well to the Jitpack repo. This answer might provide a way to also publish a source jar next to the AAR. When a source jar is also published an IDE will use Gradle to also pull the source jar into the project and will use this when implementing methods to get argument names and such.

Dries
  • 385
  • 3
  • 12
2

The solution for jitpack was adding javadoc for interfaces and this in lib gradle build file:

// build a jar with source files
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    failOnError  false
    source = android.sourceSets.main.java.sourceFiles
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.compile
}

// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}
Mateusz Kaflowski
  • 2,221
  • 1
  • 29
  • 35
1

There are two reasons why this could happen:

1. You haven't included any documentation as artifact in your AAR

If this the case then you need to add following tasks in AAR's build.gradle as follows:

task javadoc(type: Javadoc) {

    description "Generates Javadoc for ${archivesBaseName}-${version} API"
    group JavaBasePlugin.DOCUMENTATION_GROUP

    title = "${archivesBaseName}-${version} API References"

    source android.sourceSets.main.java.srcDirs, configurations.doc.collect { zipTree(it) }
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))

    options {
        memberLevel = JavadocMemberLevel.PUBLIC
        linksOffline('http://developer.android.com/reference/', "${android.sdkDirectory}/docs/reference");
    }

    include '<path of your public api>/*.java'
    exclude '**/BuildConfig.java'
    exclude '**/R.java' 
    exclude '**/test/**/*.java'

    failOnError false
}

task androidJavadocsJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives androidJavadocsJar
}

2. You have already done step 1

If this is the case you need to inform android studio to download the javaDoc. Place following code in your target app's main build.gradle

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

Alternatively, you can follow this SO to do it through android studio.

Note: You need to properly document the Javadoc download in User guide of your AAR so that user of your AAR knows how to overcome the impediment

Sagar
  • 23,903
  • 4
  • 62
  • 62