From 39b463a80079299922517820c36a1801eeedbea7 Mon Sep 17 00:00:00 2001 From: yuefeng Date: Tue, 7 Mar 2023 18:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E9=99=A4=20so=20?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=EF=BC=8C=E8=AE=A9=E4=B8=9A=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=9C=89=E5=9C=A8=E6=89=93=E5=8C=85=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E4=B8=8A=E4=BC=A0=20so=20=E5=88=B0=E4=BA=91?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E6=9C=BA=E4=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/imf/plugin/so/SoFileExtensions.kt | 11 +++++++---- .../main/kotlin/com/imf/plugin/so/SoHandle.kt | 16 ++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/file-plugin/src/main/kotlin/com/imf/plugin/so/SoFileExtensions.kt b/file-plugin/src/main/kotlin/com/imf/plugin/so/SoFileExtensions.kt index 469f243..0d78e05 100644 --- a/file-plugin/src/main/kotlin/com/imf/plugin/so/SoFileExtensions.kt +++ b/file-plugin/src/main/kotlin/com/imf/plugin/so/SoFileExtensions.kt @@ -1,5 +1,7 @@ package com.imf.plugin.so +import java.io.File + /** * 必须 open 否则 project.extensions.create 无法创建 SoFileExtensions 的代理子类 */ @@ -31,6 +33,8 @@ open class SoFileExtensions { */ var backupDeleteSo: Boolean = true + var onDeleteSo: ((File, String) -> Unit)? = null + /** * 压缩放在 assets 下的 so 库 */ @@ -41,8 +45,7 @@ open class SoFileExtensions { /** - * 是否需要保留所有依赖项 默认为保留所有只保留删除或者压缩的依赖 minSdkVersion 小于 23 则需要保留 - * 如果 minSdkVersion 大于 23 则不需要 不可手动设置 + * 是否需要保留所有依赖项 默认为保留所有只保留删除或者压缩的依赖 minSdkVersion 小于 23 则需要保留 如果 minSdkVersion 大于 23 则不需要 不可手动设置 */ var neededRetainAllDependencies: Boolean = true @@ -52,8 +55,8 @@ open class SoFileExtensions { var forceNeededRetainAllDependencies: Boolean? = null /** - * 配置自定义依赖 用于解决 a.so 并未声明依赖 b.so 并且内部通过 dlopen 打开 b.so - * 或者反射 System.loadLibrary 等跳过 hook 加载 so 库等场景 + * 配置自定义依赖 用于解决 a.so 并未声明依赖 b.so 并且内部通过 dlopen 打开 b.so 或者反射 System.loadLibrary 等跳过 hook 加载 so + * 库等场景 */ var customDependencies: Map>? = null } \ No newline at end of file diff --git a/file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt b/file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt index 71af717..b9e3de7 100644 --- a/file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt +++ b/file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt @@ -5,7 +5,6 @@ import com.elf.ElfParser import com.google.gson.Gson import java.io.File import java.io.IOException -import java.nio.file.Files import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -128,17 +127,18 @@ class SoHandle( if (result) { val parseNeededDependencies = getNeededDependenciesBySoFile(abiDir, it, deleteSoLibs, compressSo2AssetsLibs) + val md5 = getFileMD5ToString(it) recordMap[unmapLibraryName(name)] = - HandleSoFileInfo(false, getFileMD5ToString(it), parseNeededDependencies, null) + HandleSoFileInfo(false, md5, parseNeededDependencies, null) if (needDeleteInputSo) { - if (extension.backupDeleteSo && backupDir != null) { + val soFile = if (extension.backupDeleteSo && backupDir != null) { val toDir = FileUtils.mkdirs(File(backupDir.path + File.separator + it.parentFile.name)) - FileUtils.copyFile( - it, - File(toDir, it.name) - ) - } + File(toDir, it.name).apply { + FileUtils.copyFile(it, this) + } + } else it + extension.onDeleteSo?.invoke(soFile, md5) it.delete() } }