How to keep manifest file with d8 compile tool?

181 Views Asked by At

I build a jar for the Android platform with Gradle. When I use the dx command, it works well building a jar with manifest, but dx can't support Java 8 syntax. So I have to change compile tool to d8, it supports Java 8 syntax but it removes the MANIFEST.MF file. So how to keep manifest with the d8 compile tool?

Build with dx: enter image description here

Build with d8: enter image description here

Gradle build script codes:

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()
}
0

There are 0 best solutions below