Thursday, 21 May 2020

Preparing jar from Android studio library

Here is the code need to add in build gradle file to get jar file of your project module.

task makeJar(type: Copy) {    
    delete 'build/outputs/my-library-*.jar'    
    from('build/intermediates/aar_main_jar/release/')
    into('build/outputs/')
    include('classes.jar')
    rename('classes.jar', 'my-library-' + VERSION_NAME + '.jar')
}

makeJar.dependsOn(build)

Once you added the above code, sync the gradle file and click on Gradle option, which is there in right side and select the module project.
Tasks --> other --> makeJar(double click this)
Then it will start the process to generate and copy jar to "build/output/" folder.
Please go through the below images for better understanding.
* If you want to copy the jar to outside folder add "../" before the folder name
Example: into('../JarLibraryFolder/')
The above line will copy the jar file in "JarLibarayFolder" folder which is in project.



No comments:

Post a Comment