以前的代码是(这是public.xml固定资源id的public-xml.gradle)
afterEvaluate {
for (variant in android.applicationVariants) {
def scope = variant.getVariantData().getScope()
String mergeTaskName = scope.getMergeResourcesTask().name
def mergeTask = tasks.getByName(mergeTaskName)
mergeTask.doLast {
copy {
int i=0
from(android.sourceSets.main.res.srcDirs) {
include 'values/public.xml'
rename 'public.xml', (i++ == 0? "public.xml": "public_${i}.xml")
}
into(mergeTask.outputDir)
}
}
}
}
现在错误是
No signature of method: com.android.build.gradle.internal.scope.VariantScopeImpl.getMergeResourcesTask()is applicable for argument types: () values: []
Possible solutions: getMergeJavaResourcesTask()
我检查VariantScopeImp.java的代码,在3.0.1中找到代码
@Nullable private AndroidTask<MergeResources> mergeResourcesTask;
3.1.0中的代码是
@Nullable private MergeResources mergeResourcesTask;
当我将public-xml.gradle代码转换为
时def scope = variant.getVariantData().getScope()
def mergeTask = scope.mergeResourcesTask
新错误
Cannot invoke method doLast() on null object
我该怎么做?感谢
答案 0 :(得分:1)
尝试:
def mergeTask = variant.getMergeResources()
为3.1.4工作