将Gradle 4.10.1
和Android Gradle插件更新为3.3.0
,我得到以下警告:
WARNING: API '
variantOutput.getPackageApplication()
' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()
'.
该行以及周围的上下文(通过build变体分配输出文件名):
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()
}
}
}
}
migration guide不太有用;尽管
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来避免这些过时的警告?
最佳答案
variantOutput.getPackageApplication()由更改的变体API引起。
changing
output.outputFile.parent
tovariant.getPackageApplicationProvider().get().outputs.files[1]
is at least a temporary workaround.
来源:@Selvin。
variant.getExternalNativeBuildTasks()由
io.fabric
插件引起。the next version of the
io.fabric
plugin will usevariant.getExternalNativeBuildProviders()
.
资料来源:116408637; confirmation用于 promise 的修复(
1.28.1
)。这些是由
com.google.gms.google-services
引起的:registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'
这个blog post解释了如何通过添加该插件生成的XML资源来完全摆脱
com.google.gms.google-services
插件。从build/generated/res/google-services/debug/values/values.xml
到常规debug/values/values.xml
。最简单,最省力的方法可能是:
buildscript {
repositories {
google()
maven { url "https://maven.fabric.io/public" }
}
dependencies {
//noinspection GradleDependency
classpath "com.android.tools.build:gradle:3.2.1"
classpath "io.fabric.tools:gradle:1.28.1"
}
}
有关调试信息:
./gradlew -Pandroid.debug.obsoleteApi=true mobile:assembleDebug
这些
warnings
均未以任何方式改变行为。
关于gradle - variantOutput.getPackageApplication()已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54206898/