usage:
1.下载fatJar.gradle放置于project根目录
2.在project的build.gradle中添加依赖和配置:
apply from: 'fatJar.gradle' buildscript { dependencies { classpath 'xyz.bboylin:FatJarPlugin:1.0.5' } } //可配置项 fatJarExt { //这里可配置需要打包的module名和需要加入的第三方jar绝对路径 jarPaths = ["/github/okhttp.jar", "libtwo", "commonlib"] //配置需要添加assets的module名,没有可删掉此项 assetsPaths = ["libtwo","commonlib"] //最后output的jar名 output = "result.jar" //manifest中created-by的值 owner = "your name or your organization" //manifest中version的值 version = 'your sdk version' //只打debug包的话加上这句,只打release包的话不加 isDebug = true }
3.项目根目录下命令行执行gradlew fatJar
即可。
注意:
如果你的module不在项目根目录下,比如D:\MyApplication\components\libone
和D:\MyApplication\components\player\bdplayer
,D:\MyApplication
是我的项目根目录,那你不能直接写"libone",要改为"components:libone",即module用相对路径。示例:
fatJarExt { jarPaths = ["/github/okhttp.jar" ,"libtwo", ,"commonlib" ,"components:libone" ,"components:player:bdplayer"] assetsPaths = ["libtwo" ,"components:libone" ,"components:player:bdplayer"] //最后output的jar名 output = "result.jar" //manifest中created-by的值 owner = "your name or your organization" //manifest中version的值 version = 'your sdk version' //只打debug包的话加上这句,不加默认只打release包 isDebug = true }
示例
apply plugin: 'FatJarPlugin' def ROOT_BUILD_PATH = project.buildDir.absolutePath def JAR_NAME = "ParserEngine_${buildInfo.version}.jar" def BUBBLE_ASSETS_PATH = "${rootProject.rootDir.absolutePath}/Engines/BubbleEngine/src/main/assets" def CARD_PARSER_ASSETS_PATH = "${rootProject.rootDir.absolutePath}/Engines/CardEngine/src/main/assets" def BUBBLE_ASSETS_FILES = ["sms_bubble_stable_ac.index", "sms_bubble_stable_others.index", "sms_bubble_stable_regex.db"] def CARD_RULE_ASSETS_FILES = ["sms_card_stable_ac.index", "sms_card_stable_others.index", "sms_card_stable_regex.db"] def CARD_PARSER_ASSETS_FILES = ["parser.dic", "parser.zip"] def SDK_OUT_PATH = "${ROOT_BUILD_PATH}/sdk_out_temp" def SDK_ZIP_NAME = "parser_engine_${buildInfo.version}.zip" def SO_PATH = "${rootProject.rootDir.absolutePath}/ParserEngine/src/main/jniLibs" //依赖assembleDebug或者assembleRelease fatJarTask.dependsOn({ def tasks = new ArrayList<>() def taskName = fatJarExt.isDebug ? ":assembleDebug" : ":assembleRelease" fatJarExt.jarPaths.each { if (!it.contains(".jar")) { tasks.add(":" + it + taskName) } } return tasks.toArray() }) //可配置项 fatJarExt { jarPaths = ["ParserEngine", "commonlib", "ActionLib"] output = JAR_NAME owner = "parserengine_${buildInfo.version}_${buildInfo.vcs_version}_${buildInfo.build_time}" // version = buildInfo.version // isDebug = true } task copySDK(type: Copy, dependsOn: [":fatJarTask"]) { delete JAR_NAME delete SDK_OUT_PATH delete "$ROOT_BUILD_PATH/$SDK_ZIP_NAME" into('/jniLibs') { from SO_PATH } into('/libs') { from JAR_NAME } into('/assets') { def allFiles = [] allFiles.addAll(BUBBLE_ASSETS_FILES.collect { "${BUBBLE_ASSETS_PATH}/${it}" }) allFiles.addAll(CARD_PARSER_ASSETS_FILES.collect { "${CARD_PARSER_ASSETS_PATH}/${it}" }) allFiles.addAll(CARD_RULE_ASSETS_FILES.collect { "${CARD_PARSER_ASSETS_PATH}/${it}" }) from allFiles } destinationDir(file(SDK_OUT_PATH)) } task makeSDK(type: Zip, dependsOn: [copySDK]) { from SDK_OUT_PATH archiveName SDK_ZIP_NAME destinationDir(file(ROOT_BUILD_PATH)) }