Android library - how to build a jar of dependencies using gradle?

I am trying to transfer an android library project from ant to gradle , and I am completely stuck, including project dependencies in the final bank + excluding some other resources (mainly classes created using Android, such as BuildConfig, etc.).

My ant jar task looks like this:

<jar destfile="${dist}/lib/LIB_NAME.jar"
     basedir="${build.dir}/classes"
     includes="com/**"
     excludes="**/R.class, **/R$*.class, **/Manifest*.class">

     <manifest>
      <attribute name="Main-Class" value="PACKAGE"/>
     </manifest>
</jar>

I would like to achieve a similar effect using gradle + include a subset of dependencies in the final jar. My current approach is based on a Jake Wharton solution that does not bind dependencies:

android.libraryVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
        return; // Skip debug builds.
    }
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    artifacts.add('archives', task);
}

, , + ? , , - , gradle.

+4

Source: https://habr.com/ru/post/1534170/


All Articles