随着 Gradle4.10.1
和 Android Gradle 插件更新为3.3.0
,我收到以下警告:
警告:API '
variantOutput.getPackageApplication()
' 已过时并已替换为 'variant.getPackageApplicationProvider()
'。
该行带有周围的上下文(通过构建变体分配输出文件名):
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.getBuildType().getName() in rootProject.archiveBuildTypes) {
def buildType = variant.getBuildType().getName()
if (variant.versionName != null) {
def baseName = output.baseName.toLowerCase()
String fileName = "${rootProject.name}_${variant.versionName}-${baseName}.apk"
// this is the line:
outputFileName = new File(output.outputFile.parent, fileName).getName()
}
}
}
}
迁移指南不是很有帮助;虽然variant.outputs.all
可能有问题-只是不知道要替换什么-迁移指南指的是任务而不是构建变体。禁用时File → Settings → Experimental → Gradle → Only sync the active variant
,我会收到更多弃用警告(关键是,这些方法都没有被直接调用):
WARNING: API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
WARNING: API 'variantOutput.getProcessManifest()' is obsolete and has been replaced with 'variantOutput.getProcessManifestProvider()'.
WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
WARNING: API 'variant.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.
WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
问:如何通过迁移到新 API 来避免这些弃用警告?