我想在我的.aar文件中包含一个LICENSE.txt文件。我该怎么办?
提前致谢。
答案 0 :(得分:0)
您可以通过添加解压缩您的aar的Gradle任务,将许可文件复制到其中并重新压缩aar来实现此目的。
应该在'bundleRelease'任务和'uploadArchives'任务之间完成
这就是我能做到的:
android {
// (...)
def libraryModuleName = 'your-library-module-name'
def outputAarDir = rootProject.file(libraryModuleName + '/build/outputs/aar')
def outputAarUnzipedDir = rootProject.file(libraryModuleName + '/build/outputs/aar/unziped')
def aarReleaseFile = rootProject.file(libraryModuleName + '/build/outputs/aar/' + libraryModuleName + '-release.aar')
task unzipAar(type: Copy) {
from zipTree(aarReleaseFile)
into outputAarUnzipedDir
}
task addLicenseFileInUnzipedAar(type: Copy, dependsOn: 'unzipAar') {
def fromDir = rootProject.file(libraryModuleName + '/')
from fromDir
into outputAarUnzipedDir
include 'LICENSE.txt'
}
task reZipAar(type: Zip, dependsOn: 'addLicenseFileInUnzipedAar') {
from outputAarUnzipedDir
include '*'
include '*/*'
archiveName libraryModuleName + '-release.aar'
destinationDir(outputAarDir)
}
afterEvaluate {
bundleRelease.finalizedBy(reZipAar)
}
}
然后将这些任务添加到您的标准构建过程中。
构建后的gradle控制台:
(...)
:your-library-module-name:bundleRelease
:your-library-module-name:unzipAar
:your-library-module-name:addLicenseFileInUnzipedAar
:your-library-module-name:reZipAar