-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfix_issue_1263.gradle
More file actions
77 lines (73 loc) · 3.59 KB
/
fix_issue_1263.gradle
File metadata and controls
77 lines (73 loc) · 3.59 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* 这个脚本通过hook create*ApkListingFileRedirect任务,
* 在它执行完成后,即生成了apk_ide_redirect_file,也应该生成了apk之后,
* 补充一个复制build/intermediates/apk到build/outputs/apk的操作。
*
* 采用这个修复方式是因为Shadow的打包代码设计不是很合理,难以通过少量改动,
* 保证引用项目不引入任何兼容性问题。
*
* 详见issue #1263
*/
buildscript {
dependencies {
classpath files(rootProject.buildscript.configurations.classpath)
}
}
def taskList = [
":sample-loader:createDebugApkListingFileRedirect",
":sample-loader:createReleaseApkListingFileRedirect",
":sample-runtime:createDebugApkListingFileRedirect",
":sample-runtime:createReleaseApkListingFileRedirect",
":sample-manager:createDebugApkListingFileRedirect",
":sample-manager:createReleaseApkListingFileRedirect",
":sample-app:createPluginDebugApkListingFileRedirect",
":sample-app:createPluginReleaseApkListingFileRedirect",
":sample-base:createPluginDebugApkListingFileRedirect",
":sample-base:createPluginReleaseApkListingFileRedirect",
":test-dynamic-loader:createDebugApkListingFileRedirect",
":test-dynamic-loader:createReleaseApkListingFileRedirect",
":test-dynamic-runtime:createDebugApkListingFileRedirect",
":test-dynamic-runtime:createReleaseApkListingFileRedirect",
":test-dynamic-manager:createDebugApkListingFileRedirect",
":test-dynamic-manager:createReleaseApkListingFileRedirect",
":plugin-service-for-host:createPluginDebugApkListingFileRedirect",
":plugin-service-for-host:createPluginReleaseApkListingFileRedirect",
":test-plugin-androidx-cases:createPluginDebugApkListingFileRedirect",
":test-plugin-androidx-cases:createPluginReleaseApkListingFileRedirect",
":test-plugin-general-cases:createPluginDebugApkListingFileRedirect",
":test-plugin-general-cases:createPluginReleaseApkListingFileRedirect",
":sample-hello-apk:createDebugApkListingFileRedirect",
":sample-hello-apk:createReleaseApkListingFileRedirect",
]
afterEvaluate {
taskList.forEach {
def t = tasks.findByPath(it)
copyApkAfterTask(t)
}
}
def copyApkAfterTask(t) {
t.doLast {
def redirectFile = t.getOutputs().getFiles().singleFile
def listingFile = redirectFile.readLines().get(1).replaceFirst("listingFile=", "")
def metadataFile = new File(redirectFile.parentFile, listingFile)
def metadata = new org.json.JSONObject(metadataFile.text)
def outputFile = metadata.getJSONArray("elements").getJSONObject(0).getString("outputFile")
def apkFile = new File(metadataFile.parentFile, outputFile)
def testRelativePath = redirectFile.relativePath(apkFile)
def separator = java.util.regex.Pattern.quote(File.separator)
def needCopy = !testRelativePath.matches("^(\\.\\.${separator})+outputs${separator}.+")
if (needCopy) {
def matchPath = new File("/build/intermediates").toPath().toString()
def intermediatesDir = new File(apkFile.toPath().normalize().toString().find('^.+?' + java.util.regex.Pattern.quote(matchPath)))
def outputsDir = new File(intermediatesDir.parentFile, "outputs")
def r = copy {
from intermediatesDir
into outputsDir
include 'apk/**'
}
if (r.didWork) {
getLogger().info("copy apk from ${intermediatesDir.path} to ${outputsDir.path}")
}
}
}
}