Skip to content

Commit 5db9fd4

Browse files
committed
修改脚本
1 parent 496d074 commit 5db9fd4

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ dependencies {
147147
// implementation 'androidx.navigation:navigation-ui-ktx:2.5.0'
148148
// implementation 'org.greenrobot:eventbus:3.1.1'
149149
}
150+
apply from: "$rootDir/gradle/deleteOccupancy.gradle"

gradle/deleteOccupancy.gradle

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11

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+
29
android.applicationVariants.configureEach {
310
def variantName = name
411
tasks.matching { it.name.endsWith("AssembleAndroidAopTask") && it.name.contains(variantName) }.configureEach {
512
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+
}
817
}
918
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+
}
1423
}
1524
}
1625
}
@@ -49,23 +58,30 @@ def restoreOriginalFile(){
4958
}
5059
}
5160

52-
println "恢复 ${allFiles.size()} 个文件:"
5361

62+
def count = 0
5463
for (final File file in allFiles) {
5564
File sourceFile = new File(project.rootProject.buildDir.parentFile.absolutePath,file.getAbsolutePath().replace(rootDir.getAbsolutePath(),""))
5665
if (!sourceFile.exists()){
5766
copyFile(file,sourceFile)
67+
count++
5868
}
5969
file.delete()
6070
}
71+
72+
println "恢复了 ${count} 个备份文件:"
73+
if (rootDir.exists()) {
74+
rootDir.deleteDir()
75+
}
6176
}
6277

78+
//测试使用
6379
task aaTestDelete() {
6480
doLast {
65-
deleteOnSave("test-lib/build/intermediates/compile_symbol_list/debug/R.txt")
81+
backupOriginalFile()
6682
}
6783
}
68-
84+
//测试使用
6985
task aaTestRestore() {
7086
doLast {
7187
restoreOriginalFile()

0 commit comments

Comments
 (0)