mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Added ClassLoader Conflict Problem in host-inject documentation
This commit is contained in:
@@ -284,4 +284,49 @@ You can refer to the **Module App Demo** in this case and see [here is the sampl
|
||||
|
||||
For more functions, please refer to the [Context.applyModuleTheme](../public/com/highcapable/yukihookapi/hook/factory/YukiHookFactory#context-applymoduletheme-ext-method) method.
|
||||
|
||||
:::
|
||||
|
||||
## ClassLoader Conflict Problem
|
||||
|
||||
The content introduced on this page is to directly inject the resources of the Module App into the Host App.
|
||||
|
||||
Since the Module App and the Host App are not in the same process (the same **APK**), there may be a `ClassLoader` conflict.
|
||||
|
||||
If a `ClassLoader` conflict occurs, you may encounter a `ClassCastException`.
|
||||
|
||||
`YukiHookAPI` has solved the problem of possible conflicts by default, and you need to configure the exclusion list by yourself in other cases.
|
||||
|
||||
The exclusion list determines whether these `Class` need to be loaded by the Module App or the Host App's `ClassLoader`.
|
||||
|
||||
> The following example
|
||||
|
||||
```kotlin
|
||||
// Exclude Class names belonging to the Host App
|
||||
// They will be loaded by the Host App's ClassLoader
|
||||
// ❗The following content is for demonstration only
|
||||
// DO NOT USE IT DIRECTLY, please refer to your actual situation
|
||||
ModuleClassLoader.excludeHostClasses(
|
||||
"androidx.core.app.ActivityCompat",
|
||||
"com.demo.Test"
|
||||
)
|
||||
// Exclude Class names belonging to the Module App
|
||||
// They will be loaded by the ClassLoader of the Module App (the current Hook process)
|
||||
// ❗The following content is for demonstration only
|
||||
// DO NOT USE IT DIRECTLY, please refer to your actual situation
|
||||
ModuleClassLoader.excludeModuleClasses(
|
||||
"com.demo.entry.HookEntry",
|
||||
"com.demo.controller.ModuleController"
|
||||
)
|
||||
```
|
||||
|
||||
You need to set it before the method of injecting Module App's resources into the Host App is executed to take effect.
|
||||
|
||||
This function is only to solve the situation that **`Class` with the same name** may exist in the Host App and Module App, such as shared SDK and dependencies.
|
||||
|
||||
In most cases, you will not use this function.
|
||||
|
||||
::: tip
|
||||
|
||||
For more functions, please refer to [ModuleClassLoader](../public/com/highcapable/yukihookapi/hook/xposed/parasitic/reference/ModuleClassLoader).
|
||||
|
||||
:::
|
@@ -272,4 +272,43 @@ injectMember {
|
||||
|
||||
更多功能请参考 [Context.applyModuleTheme](../public/com/highcapable/yukihookapi/hook/factory/YukiHookFactory#context-applymoduletheme-ext-method) 方法。
|
||||
|
||||
:::
|
||||
|
||||
## ClassLoader 冲突问题
|
||||
|
||||
本页面所介绍的内容都是直接将模块的资源注入到了宿主,由于模块与宿主不在同一个进程 (同一个 **APK**) 中,其可能存在 `ClassLoader` 冲突的问题。
|
||||
|
||||
若发生了 `ClassLoader` 冲突,你可能会遇到 `ClassCastException` 异常。
|
||||
|
||||
`YukiHookAPI` 默认已解决了可能冲突的问题,其余情况需要你自行配置排除列表。
|
||||
|
||||
排除列表决定了这些 `Class` 需要被模块还是宿主的 `ClassLoader` 进行装载。
|
||||
|
||||
> 示例如下
|
||||
|
||||
```kotlin
|
||||
// 排除属于宿主的 Class 类名
|
||||
// 它们将会被宿主的 ClassLoader 装载
|
||||
// ❗以下内容仅供演示,不要直接使用,请以你的实际情况为准
|
||||
ModuleClassLoader.excludeHostClasses(
|
||||
"androidx.core.app.ActivityCompat",
|
||||
"com.demo.Test"
|
||||
)
|
||||
// 排除属于模块的 Class 类名
|
||||
// 它们将会被模块 (当前 Hook 进程) 的 ClassLoader 装载
|
||||
// ❗以下内容仅供演示,不要直接使用,请以你的实际情况为准
|
||||
ModuleClassLoader.excludeModuleClasses(
|
||||
"com.demo.entry.HookEntry",
|
||||
"com.demo.controller.ModuleController"
|
||||
)
|
||||
```
|
||||
|
||||
你需要在向宿主注入模块资源的方法执行之前进行设置才能生效。
|
||||
|
||||
此功能仅为解决宿主与模块中可能存在**同名的 `Class`** 情况,例如共用的 SDK 以及依赖,在大部分情况下你不会用到此功能。
|
||||
|
||||
::: tip
|
||||
|
||||
更多功能请参考 [ModuleClassLoader](../public/com/highcapable/yukihookapi/hook/xposed/parasitic/reference/ModuleClassLoader)。
|
||||
|
||||
:::
|
Reference in New Issue
Block a user