|
1 | 1 |
|
| 2 | +def backupOriginalFile(){ |
| 3 | + //在此写上占用的文件,路径就填相对当前项目的相对路径即可,以此尝试解决windows电脑文件占用的问题 |
| 4 | + deleteOnSave("/test-lib/build/intermediates/runtime_library_classes_jar/debug/classes.jar") |
| 5 | + deleteOnSave("/test-lib/build/intermediates/compile_library_classes_jar/debug/classes.jar") |
| 6 | +} |
| 7 | + |
| 8 | + |
2 | 9 | android.applicationVariants.configureEach { |
3 | 10 | def variantName = name |
4 | 11 | tasks.matching { it.name.endsWith("AssembleAndroidAopTask") && it.name.contains(variantName) }.configureEach { |
5 | 12 | doFirst { |
6 | | - println("Before AOP for variant $variantName") |
7 | | - restoreOriginalFile() |
| 13 | + if (System.getProperty("os.name").toLowerCase().contains("win")) { |
| 14 | + println("Before AOP for variant $variantName") |
| 15 | + restoreOriginalFile() |
| 16 | + } |
8 | 17 | } |
9 | 18 | doLast { |
10 | | - println("After AOP for variant $variantName") |
11 | | - //在此写上占用的文件,路径就填相对当前项目的相对路径即可,以此尝试解决windows电脑文件占用的问题 |
12 | | - deleteOnSave("/test-lib/build/intermediates/runtime_library_classes_jar/debug/classes.jar") |
13 | | - deleteOnSave("/test-lib/build/intermediates/compile_library_classes_jar/debug/classes.jar") |
| 19 | + if (System.getProperty("os.name").toLowerCase().contains("win")) { |
| 20 | + println("After AOP for variant $variantName") |
| 21 | + backupOriginalFile() |
| 22 | + } |
14 | 23 | } |
15 | 24 | } |
16 | 25 | } |
@@ -49,23 +58,30 @@ def restoreOriginalFile(){ |
49 | 58 | } |
50 | 59 | } |
51 | 60 |
|
52 | | - println "恢复 ${allFiles.size()} 个文件:" |
53 | 61 |
|
| 62 | + def count = 0 |
54 | 63 | for (final File file in allFiles) { |
55 | 64 | File sourceFile = new File(project.rootProject.buildDir.parentFile.absolutePath,file.getAbsolutePath().replace(rootDir.getAbsolutePath(),"")) |
56 | 65 | if (!sourceFile.exists()){ |
57 | 66 | copyFile(file,sourceFile) |
| 67 | + count++ |
58 | 68 | } |
59 | 69 | file.delete() |
60 | 70 | } |
| 71 | + |
| 72 | + println "恢复了 ${count} 个备份文件:" |
| 73 | + if (rootDir.exists()) { |
| 74 | + rootDir.deleteDir() |
| 75 | + } |
61 | 76 | } |
62 | 77 |
|
| 78 | +//测试使用 |
63 | 79 | task aaTestDelete() { |
64 | 80 | doLast { |
65 | | - deleteOnSave("test-lib/build/intermediates/compile_symbol_list/debug/R.txt") |
| 81 | + backupOriginalFile() |
66 | 82 | } |
67 | 83 | } |
68 | | - |
| 84 | +//测试使用 |
69 | 85 | task aaTestRestore() { |
70 | 86 | doLast { |
71 | 87 | restoreOriginalFile() |
|
0 commit comments