0

I'm developing a library on Android Studio (a SDK, let's say module A). To test it out, I also got a demoApp

I also have another lib with the SDK dependencies (a plugin, let's say module B)

So in my project, there are 3 modules : the SDK (A), the demoApp and the plugin (B)

Now I need to distribute my SDK and / or my plugin in jar files so people can use it in their project

The question is : how can I generate a jar for the SDK and a jar for the plugin (including all the necessaries dependencies of course like jar in libs folder) with Gradle tasks (I don't need any ressources or assets) ?

I'm very new to Gradle, I cross this answer but I don't know if it match my needs (need to be Android compatible)

EDIT : to clarify I added letter

  • I need a jar file for A
  • B need A to run (dependencies)
  • I need a jar file for B
Community
  • 1
  • 1
Plumillon Forge
  • 1,659
  • 1
  • 16
  • 31
  • IMHO you now should use AAR files for distributed libraries (goes automatically into *build/outputs/aar/*). – shkschneider Apr 28 '15 at 14:23
  • As for your answer: it's a possible duplicate of: https://stackoverflow.com/a/19484146/603270 – shkschneider Apr 28 '15 at 14:25
  • I should but I must be Eclipse or any IDE compatible. Most people use jar :s I just read your link, someone in the comment mention it doesn't pack all dependencies http://stackoverflow.com/questions/19307341/android-library-gradle-release-jar/19484146#comment34675963_19484146 – Plumillon Forge Apr 28 '15 at 14:44

1 Answers1

1

You need to create a new gradle task, similar to mine

task clearJar(type: Delete) {
    delete '../location/' + LIBRARY_NAME + '_' + LIBRARY_VERSION + '.jar'
}

task makeJar(type: Copy) {
    dependsOn clearJar, build
    from 'build/intermediates/bundles/release/'
    into '../../location/'
    include 'classes.jar'
    rename 'classes.jar', LIBRARY_NAME + '_' + LIBRARY_VERSION + '.jar'
}

Where LIBRARY_NAME and LIBRARY_VERSION are strings I set at the top of the gradle build file.

You can add this task and then select it like this

this

Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59
  • It seems sexy ! Thanks, I will try it. Can this be used with "chaining" ? I mean this will probably work for the SDK but what about the plugin which need the SDK ? – Plumillon Forge Apr 28 '15 at 14:47
  • @PlumillonForge If you want to chain it, remove the dependency on build and call it from assemble doLast – Bojan Kseneman Apr 28 '15 at 15:06
  • by chaining I actually meant doing a jar with the SDK + Plugin sources (see my case) for the plugin module. Will your solution work for this ? Or should I makeJar for the SDK, move the result jar to plugin libs (which got /libs dependencies) then makeJar the plugin ===> The goal is to have one file for the plugin (I edited my post to clarify) – Plumillon Forge Apr 28 '15 at 16:48
  • Yes, it will work. You can do magic with gradle. First build library with make jar.. In the function you can specify where to put it. Then add a linke in makeJar that runs the other build. – Bojan Kseneman Apr 28 '15 at 19:10
  • Oki, I'll work on your solution tomorrow and mark it accepted if it's what I'm looking for :) – Plumillon Forge Apr 28 '15 at 19:49
  • Finally done it, I end up not doing the same (had to build one jar from multiple projects) but you definitively point me in the right direction, thanks – Plumillon Forge Apr 30 '15 at 09:29