Skip to content

Commit 3daba89

Browse files
committed
Update BuildScript
1 parent 5fc2d87 commit 3daba89

File tree

1 file changed

+18
-44
lines changed

1 file changed

+18
-44
lines changed

PluginMain/host.gradle

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,66 +18,39 @@ import javax.xml.parsers.SAXParserFactory
1818
////////////////////////////////////////////////////////////////
1919
////////////////////////////////////////////////////////////////
2020

21+
//第3件事
2122
android.aaptOptions.additionalParameters("-P", project.buildDir.absolutePath + "/outputs/generated_exported_all_resouces.xml")
2223

23-
tasks.whenTaskAdded { task ->
24-
if (task.name.startsWith("merge") && task.name.endsWith("Resources") && !task.name.contains("AndroidTest")) {
25-
26-
//编译宿主资源时将public.xml插入各个buildtype中
27-
task.doLast {
24+
afterEvaluate {
25+
for (variant in android.applicationVariants) {
26+
def scope = variant.getVariantData().getScope()
27+
String mergeTaskName = scope.getMergeResourcesTask().name
28+
def mergeTask = tasks.getByName(mergeTaskName)
29+
//第1件事
30+
mergeTask.doLast {
2831
copy {
2932
from(project.getProjectDir()) {
3033
include 'public.xml'
3134
}
32-
String dirName = task.name.replace("merge", "").replace("Resources", "");
33-
//这里最好再增加一个buildType判断,而不是写死Debug和Release两种
34-
if (dirName.equals("Debug") || dirName.equals("Release")) {
35-
into("${project.buildDir}/intermediates/res/merged/" + dirName.toLowerCase() + "/values/")
36-
} else if (dirName.endsWith("Debug")) {
37-
into("${project.buildDir}/intermediates/res/merged/" + dirName.replace("Debug", "") + "/debug/values/")
38-
} else if (dirName.endsWith("Release")) {
39-
into("${project.buildDir}/intermediates/res/merged/" + dirName.replace("Release", "") + "/release/values/")
40-
}
35+
into(mergeTask.outputDir.absolutePath + "/values/")
4136
}
4237
}
43-
}
44-
45-
if (task.name.startsWith("process") && task.name.endsWith("Resources") && !task.name.contains("AndroidTest")) {
46-
47-
//宿主资源编译完成后,将资源包复制到output目录备用,非独立插件编译时会读取这个资源 ap_ 文件
48-
task.doLast {
49-
copy {
50-
String name = task.name.replace("process", "").replace("Resources", "");
51-
//这里最好再增加一个buildType判断,而不是写死Debug和Release两种
52-
if (name.equals("Debug") || name.equals("Release")) {
53-
name = "resources-" + name.toLowerCase() + ".ap_";
54-
} else if (name.endsWith("Debug")) {
55-
name = "resources-" + name.replace("Debug", "") + "-debug.ap_";
56-
} else if (name.endsWith("Release")) {
57-
name = "resources-" + name.replace("Release", "") + "-release.ap_";
58-
}
59-
60-
from("${project.buildDir}/intermediates/res/") {
61-
include name
62-
}
63-
if (task.name.endsWith("DebugResources")) {
64-
into("${project.buildDir}/outputs/")
65-
rename { String fileName ->
66-
'resources-debug.ap_'
67-
}
68-
} else if (task.name.endsWith("ReleaseResources")) {
38+
//第2件事
39+
for (baseVariant in variant.outputs) {
40+
def processResourcesTask = baseVariant.getProcessResources();
41+
processResourcesTask.doLast {
42+
copy {
43+
from processResourcesTask.packageOutputFile
6944
into("${project.buildDir}/outputs/")
70-
rename { String fileName ->
71-
'resources-release.ap_'
72-
}
7345
}
7446
}
7547
}
7648
}
7749
}
7850

51+
//第4件事
7952
build.doLast {
80-
//导出主题patch,非独立插件编译时会依赖此patch
53+
//导出主题debug patch,非独立插件编译时会依赖此patch
8154
createThemePatch();
8255
}
8356

@@ -90,6 +63,7 @@ def createThemePatch() {
9063
ThemeProcessor.exportThemeStyle(new File(project.buildDir.absolutePath + "/outputs/generated_exported_all_resouces.xml"),
9164
new File(patchDir, "patch_theme.xml"), android.defaultConfig.applicationId)
9265

66+
//debug模式下的目录,这里hardcode太多啦。。。。囧
9367
String parenDir = "${project.buildDir}/intermediates/res/merged/debug/";
9468

9569
ThemeProcessor.exportThemeStyle(new File(parenDir + "values/values.xml"),

0 commit comments

Comments
 (0)