Unable to overwrite the manifest with gradle plugi

2019-04-15 01:09发布

This is basically a copy of the text that I wrote in this issue

Any help would be appreciated:

I'm trying to upgrade my project to gradle plugin 3.3 w/ gradle 4.10.1 and my build fails with the following error

  • What went wrong: Execution failed for task ':main:processDebugManifest'.

    java.io.FileNotFoundException: /main/property(interface org.gradle.api.file.Directory, transform(property(interface org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultProjectLayout$FixedDirectory, /main/build))))/AndroidManifest.xml (No such file or directory)

my code is identical to the code here - https://developer.android.com/studio/known-issues#variant_api under "manifestOutputFile is no longer available"

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.processManifest.doLast {
            // Stores the path to the maifest.
            String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
            // Stores the contents of the manifest.
            def manifestContent = file(manifestPath).getText()
...
        }
    }
}

and this is the line that produces the error -

def manifestContent = file(manifestPath).getText()

Update: tried the solution suggested in the comment below this answer and got the following error

  • What went wrong: Execution failed for task ‘:main:processDebugManifest’. Could not find matching constructor for: java.io.File(org.gradle.api.internal.file.DefaultProjectLayout$DefaultDirectoryVar, java.lang.String)

2条回答
Animai°情兽
2楼-- · 2019-04-15 02:01

Try replacing

String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"

with

String manifestPath = new File(output.processManifest.manifestOutputDirectory.get().asFile, "AndroidManifest.xml")

查看更多
姐就是有狂的资本
3楼-- · 2019-04-15 02:05
def outputDir = manifestOutputDirectory
File directory
if (outputDir instanceof File) {
    directory = outputDir
} else {
    directory = outputDir.get().asFile
}

String manifestPath = directory.toString() + "/AndroidManifest.xml"
查看更多
登录 后发表回答