我用 Gradle 为 Android 平台构建了一个 jar。当我使用该dx
命令时,它可以很好地构建一个带有清单的 jar,但dx
不支持 Java 8 语法。所以我必须将编译工具更改为d8
,它支持 Java 8 语法但它删除了MANIFEST.MF
文件。那么如何使用d8
编译工具来保存manifest呢?
Gradle 构建脚本代码:
def jarPath = buildDir.absolutePath + "/libs"
def jarBaseName = "plugin"
task buildJar(dependsOn: build, type: Jar) {
doFirst {
manifest {
attributes 'Jar-VersionCode': jarVersionCode
}
}
from zipTree(file('build/intermediates/aar_main_jar/release/classes.jar'))
// [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
archiveBaseName = jarBaseName
archiveAppendix = null
archiveVersion = "$jarVersionName-$jarVersionCode"
archiveClassifier = "release"
archiveExtension = "jar"
destinationDirectory = file(jarPath)
}
// dx --dex --output=output.jar input.jar
task buildDex1(dependsOn: buildJar, type: Exec) {
workingDir jarPath
executable "dx"
args "--dex"
args "--output=" + buildJar.archiveFileName.get()
args buildJar.archiveFileName.get()
}
// d8 --release --output output.jar input.jar
task buildDex2(dependsOn: buildJar, type: Exec) {
workingDir jarPath
executable "d8"
args "--release"
args "--output"
args buildJar.archiveFileName.get()
args buildJar.archiveFileName.get()
}