Record the process of exporting jar package in Android studio 3.2

Time:2021-1-17
  • 1.) description.

This project is from rottools, a project on GitHub(https://github.com/Stericson/RootTools )Here, I just want to output the jar package after local compilation for my own use.

  • 2.) operation steps.

Step 1) develop the project to be output as jar in the way you are familiar with before

Step 2) general gradle settings, such as gradle version, Android SDK compilation, target, minimum required version, JDK version settings of compileoptions, etc

Step 3) apply plugin settings in gradle:

apply plugin: ' com.android.library '// here is the key point. The front application plugin:' com.android.application 'modify to apply plugin: ' com.android.library 'application corresponds to APK

Step 4) output task configuration of jar

//Starting from here is the gradle setting of the export jar
task copyJar(type: Copy) {
    delete 'build/outputs/ RootTools.jar '// delete the previous old jar package
    Archivesbasename = code // jar package name
    From ('build / intermediates / intermediate jars / release ') // here is the compiled code classes.jar , res.jar Package directory (different as versions are different, according to their own)
    Into ('build / LIBS') // jar package output directory
    include(' classes.jar '// copy the code jar package, fixed call classes.jar
    rename(' classes.jar ', ' RootShell.jar '// rename the name of the jar package
}
copyJar.dependsOn(build)

Step 5) syncnow and execute related tasks