-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpublic-xml.gradle
42 lines (41 loc) · 1.75 KB
/
public-xml.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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")
}
//[/Users/tanzx/AndroidStudioProjects/AaptDemo/app/src/main/res]
println("tanzhenxing:${android.sourceSets.main.res.srcDirs}")
///Users/tanzx/AndroidStudioProjects/AaptDemo/app/build/intermediates/res/merged/debug
println("tanzhenxing:${mergeTask.outputDir}")
into(mergeTask.outputDir)
}
}
getResOutputDir(getProcessResourcesTask(project, variant))
}
}
static def getProcessResourcesTask(project, variant) {
return project.tasks.findByName("process${variant.name.capitalize()}Resources")
}
/**
* 获取资源输出目录
* @param processResources
*/
static void getResOutputDir(Object processResources) {
File resDir = null
if (processResources.properties['resDir'] != null) {
resDir = processResources.resDir
} else if (processResources.properties['inputResourcesDir'] != null) {
resDir = processResources.inputResourcesDir.getFiles().first()
}
String str = resDir.absolutePath
//str=/Users/tanzx/AndroidStudioProjects/AaptDemo/app/build/intermediates/res/merged/debug
//str=/Users/tanzx/AndroidStudioProjects/AaptDemo/app/build/intermediates/res/merged/release
println("tanzhenxing:str=${str}")
}