Skip to content

Commit

Permalink
添加移除 so 回调,让业务端可以有在打包过程中上传 so 到云端的机会
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxinyu committed Mar 7, 2023
1 parent 7f254ce commit 39b463a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.imf.plugin.so

import java.io.File

/**
* 必须 open 否则 project.extensions.create 无法创建 SoFileExtensions 的代理子类
*/
Expand Down Expand Up @@ -31,6 +33,8 @@ open class SoFileExtensions {
*/
var backupDeleteSo: Boolean = true

var onDeleteSo: ((File, String) -> Unit)? = null

/**
* 压缩放在 assets 下的 so 库
*/
Expand All @@ -41,8 +45,7 @@ open class SoFileExtensions {


/**
* 是否需要保留所有依赖项 默认为保留所有只保留删除或者压缩的依赖 minSdkVersion 小于 23 则需要保留
* 如果 minSdkVersion 大于 23 则不需要 不可手动设置
* 是否需要保留所有依赖项 默认为保留所有只保留删除或者压缩的依赖 minSdkVersion 小于 23 则需要保留 如果 minSdkVersion 大于 23 则不需要 不可手动设置
*/
var neededRetainAllDependencies: Boolean = true

Expand All @@ -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<String, List<String>>? = null
}
16 changes: 8 additions & 8 deletions file-plugin/src/main/kotlin/com/imf/plugin/so/SoHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 39b463a

Please sign in to comment.