1. New test project, two Module,app is Android project, MyLibrary is the Android library.
2. Open the Build.gradle file in the MyLibrary directory and add the following code block.
task Makejar (type:copy) {Delete'Build/libs/mylibrary.jar' //Delete a jar package that already exists from('build/intermediates/bundles/release/')//load the files to be packaged from this directoryInto'build/libs/')//Save directory for jar packagesInclude'Classes.jar')//set filters, package only classes filesRename'Classes.jar','Mylibrary.jar')//Rename , Mylibrary.jar set according to your own needs}makejar.dependson (build)
3. Enter the Gradlew Makejar command in the as Terminal window.
4. Run the above command (the first time will automatically download the required dependencies, a little longer), the result is as follows, packaging is successful.
5. Copy the generated jar package for use by other projects
If the following error occurs when you run the Gradlew makejar command (MyLibrary is the name of my library):
for ' : Mylibrary:lint ' . in the project; Aborting build.
In the Build.gradle file under the MyLibrary directory, add the following code block (note where the code block is located), and re-execute the gradlew makejar command:
lintoptions { false }
Android Studio to play module into jar package