警告:API'variantOutput.getPackageApplication()'已过时

时间:2019-05-03 03:11:22

标签: android gradle

将“ Android Gradle插件”升级到3.4.0之后,我在/app/build.gradle中收到警告消息

  

警告:API'variantOutput.getPackageApplication()'已过时,并已替换为'variant.getPackageApplicationProvider()'。   它将在2019年底删除。
  有关更多信息,请参见https://d.android.com/r/tools/task-configuration-avoidance
  要确定调用variantOutput.getPackageApplication()的内容,请在命令行上使用-Pandroid.debug.obsoleteApi = true显示更多信息。

我已按照建议在“ gradle.properties”中尝试了“ android.debug.obsoleteApi = true”,然后得到了此消息。

  

原因:调用方:[android项目路径] /app/build.gradle:31

包含第31行的代码是下面的代码。

android {

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    project.ext { appName = 'my_app' }
                    def newName = output.outputFile.name
                    newName = newName.replace("app-", "$project.ext.appName-")
                    newName = newName.replace("-release", "-" + defaultConfig.versionName)
                    def relativeRootDir = output.packageApplication.outputDirectory.toPath().relativize(rootDir.toPath()).toFile()
                    output.outputFileName = new File("$relativeRootDir/", newName)
                }
            }
        }
    }
}

第31行是

def newName = output.outputFile.name

这部分是否使用API​​'variantOutput.getPackageApplication()'?我该怎么办才能解决此警告?

1 个答案:

答案 0 :(得分:0)

在我将'app / build.gradle'更改为不使用第31行之后,警告消息消失了。

    applicationVariants.all { variant ->
        variant.outputs.all {
            project.ext { appName = 'my_app' }
            def newName = outputFileName
            newName = newName.replace("app-", "$project.ext.appName-")
            newName = newName.replace("-release", "-" + defaultConfig.versionName)
            outputFileName = "${variant.name}" + newName
        }
    }
相关问题