Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio export jar with dependencies

I had a project library in Eclipse with Maven and the generated jar included some libraries dependencies inside. Now I am migrating to Android Studio and I would like to build the same jar. I can generate a jar with the following lines in gradle:

task clearJar(type: Delete) {
  delete 'build/libs/mysdk.jar'
}

task makeJar(type: Copy) {
  from('build/intermediates/bundles/release/')
  into('release/')
  include('classes.jar')
  rename ('classes.jar', 'mysdk.jar')
}

makeJar.dependsOn(clearJar, build)

But inside the jar there are not included the libraries that I use in my project library. With Maven I can use the "provided" scope in order to include or not a library in my jar but with gradle... how can I do that?

Thanks

like image 491
esteban Avatar asked Dec 11 '14 12:12

esteban


1 Answers

Solved with the following tasks:

task jarTask(type: Jar) {
 baseName="my-sdk-android"
 from 'src/main/java'
}

task createJarWithDependencies(type: Jar) {
  baseName = "my-sdk-android-jar-with-dependencies"

  from {
    configurations.compile.collect {
        it.isDirectory() ? it : zipTree(it)
    }

  }

  with jarTask
}

configurations {
  jarConfiguration
}

artifacts {
  jarConfiguration jarTask
}
like image 194
esteban Avatar answered Oct 30 '22 19:10

esteban