Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

android - Build library jar with Gradle

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...