title: Include jar file with Java sources in Android aar
body: <p>I have a gradle task to create a jar file containing Java <em>source files</em> to be included in an Android aar library package. These files will serve as Javadoc for JNI to a C++ library also bundled in the aar package.</p>
  
  <p>I cannot possibly figure out how to <em>include</em> the jar file and not <em>compile</em> the files within. it seems that the Java files in the jar file are <em>compiled</em>, which does not help me - I just want to <em>include</em> them so that they are available to developers using that aar package.</p>
  
  <p>The created jar file has all the sources and is in the output aar inside its <code>libs</code> directory, but it has no contents.</p>
  
  <p>How can I add the Java sources to my aar?</p>
  
  <p><strong>Jar creation</strong></p>
  
  <p>The Jar is created as follows and ends up in the <code>build/libs</code> folder of my module.</p>
  
  <pre><code>task generateMySources(type: Jar) {
      classifier = 'sources'
      from android.sourceSets.main.java.srcDirs
  }
  
  artifacts {
      archives generateMySources
  }
  
  preBuild.dependsOn(":myModule:generateMySources")
  
  dependencies {
      // The jar is included but it is empty inside the aar.
      compile files('build/libs/myModule-sources.jar')
  }
  </code></pre>
  
  <p>The output jar contains:</p>
  
  <pre><code>.
  ├── com
  │   └── my
  │       └── app
  │           └── jni
  │               ├── File1.java
  │               ├── File2.java
  │               ├── File3.java
  │               └── File4.java
  └── META-INF
      └── MANIFEST.MF // Contains "Manifest-Version: 1.0" only.
  </code></pre>
  
  <p>The jar exists inside the aar inside the <code>libs</code> directory, but now it is empty.</p>