API 'variantOutput.getProcessManifest()'已过时。

3

我正在尝试更改版本代码、版本名称和应用程序图标。以下是我的代码:

    variant.outputs.all { output ->
        def newApkName
        if (output.zipAlign) {
            newApkName = "Application.apk"
        }

        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()
            // Changes the version code in the stored text.
            manifestContent = manifestContent.replace('android:versionName="dev_build"',
                    String.format('android:versionName="%s"', variant.versionName))
            // Overwrites the manifest with the new text.
            file(manifestPath).write(manifestContent)
        }

        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()
            // Changes the version code in the stored text.
            manifestContent = manifestContent.replace('android:icon="@drawable/app_icon_main"',
                    String.format('android:icon="@drawable/%s"', getVersionIconName()))
            // Overwrites the manifest with the new text.
            file(manifestPath).write(manifestContent)
        }

        outputFileName = "Application.apk"
    }

收到以下警告: 警告:API“variantOutput.getProcessManifest()”已过时,已被替换为“variantOutput.getProcessManifestProvider()”。 它将在2019年底删除。 有关更多信息,请参见https://d.android.com/r/tools/task-configuration-avoidance。 要确定是什么调用了variantOutput.getProcessManifest(),请在命令行上使用-Pandroid.debug.obsoleteApi = true显示堆栈跟踪。 受影响模块:Application
环境详细信息: Android Studio:3.3.1 Gradle版本:4.10.0 构建工具版本28.0.2

所以更改方法调用。 - Zoe stands with Ukraine
1
我已经尝试更改方法名称,但仍然出现以下错误。 错误:无法获取类型为com.android.build.gradle.internal.api.ApkVariantOutputImpl的ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=devDebug, filters=[], versionCode=1000, versionName=dev_build}}的未知属性“ProcessManifestProvider”。 - Satyam Garg
@SatyamGarg,有什么进展吗? - Kamen Dobrev
1个回答

1
将以下内容更改
output.processManifest.doLast {
    //your code
}

带着。
output.getProcessManifestProvider().get().doLast {
    //your code
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接