Moudle for the library type in Android studio, so to export the jar package, we first need to put the code we want to export into a moudle.
1. Under current engineering, File--new--new Module
2. Add the function code to be exported in the module
3. Introduce the module in the app
Add the dependency of this module to the app's Build.gradle, as follows:
dependencies {compile ' com.android.support:appcompat-v7:21.0.3 ' Compile project (': MyLibrary ')}
4. Compile the project and you can see that the jar package has been generated in the path.
./mylibrary/build/intermediates/bundles/debug/classes . Jar
./mylibrary/build/intermediates/bundles/release/classes . Jar
5. Manually change the Classes.jar to the desired name, and the other functions can be used to import the jar package.
6. You can also change the 5th step to a jar package that automatically generates the required names by adding a task to the Build.gradle in Moudle:
Task Makejar (type:copy) {delete ' Build/libs/mysdk.jar ' from (' build/intermediates/bundles/release/') into (' Build /libs/') include (' Classes.jar ') rename (' Classes.jar ', ' Mysdk.jar ')}makejar.dependson (build) then execute the build jar package at the terminal./gradlew Makejar this way, you can see the jar package in the module's Libs directory.
Btw
If you want to remove the module, you must first "subtract" the module in File->project structure to be available in the project by the DELETE key of the module's right-click.
This article is from the "whatever957" blog, make sure to keep this source http://whatever957.blog.51cto.com/6835003/1791548
Android Studio Export Jar Package