Android Studio生成Jar文件

首先,你想要打包成Jar的Module项目必须是Library

1.在要生成jar库的Module->build.gradle最下面添加如下语句

 def SDK_BASENAME = "jni";//SDK名
 def SDK_VERSION = "_V1.0";//SDK版本号
 def sdkDestinationPath = "build";
 def zipFile = file('build/intermediates/bundles/release/classes.jar')//路径
 task deleteBuild(type: Delete) {
 delete sdkDestinationPath + SDK_BASENAME + SDK_VERSION + ".jar"
}//生成的包名
task makeJar(type: Jar) {
from zipTree(zipFile)
from fileTree(dir: 'src/main',includes: ['assets/**'])//将assets目录打入jar包
baseName = SDK_BASENAME + SDK_VERSION
destinationDir = file(sdkDestinationPath)}
makeJar.dependsOn(deleteBuild, build)

2.打开gradle projects

image.png

3.打开Library->Tasks->other-makeJar,双击makeJar

我是将application改成Library.png

4.双击makeJar后,run会显示打包过程

image.png

5.打包完成后,可以在Library->build中找到生成的jar库,复制出,即可使用

image.png

你可能感兴趣的:(Android Studio生成Jar文件)