Project 的 settings.gradle.ktx 添加仓库
dependencyResolutionManagement {
repositories {
// ...
maven("https://jitpack.io")
}
}Module 的 build.gradle.ktx 添加依赖框架
dependencies {
compileOnly("com.github.Xiaolangs:sweet_plugins:1.0.13")
}class InitHooker : BaseIHookXposedInit() {
override fun PackageParam.load() {
///这里面就可以开始的插件之旅
}
}在AndroidManifest中通过meta-data申明:
sweetModule: 是否甜萝插件sweetDescription: 该模块描述sweetAuthor: 该模块作者
<application .....>
<meta-data
android:name="sweetModule"
android:value="true" />
<meta-data
android:name="sweetDescription"
android:value="描述" />
<meta-data
android:name="sweetAuthor"
android:value="作者" />
</application>com.sweet.plugins.InitHookerobject ChatHooker: BaseHooker() {
override fun hook() {
}
}class InitHooker : BaseIHookXposedInit() {
override fun PackageParam.load() {
//载入ChatHooker
loadHooker(ChatHooker)
}
}///进行资源注入
curPluginsHelper?.injectPluginAppResources()在使用以下功能之前,为防止资源 ID 互相冲突,你需要在当前项目的 build.gradle.ktx 中修改资源 ID。
android {
androidResources.additionalParameters += listOf("--allow-reserved-package-id", "--package-id", "0x65")
}object GlobalPluginConfig {
private var pluginsHelper: WeakReference<PluginsHelper>? = null
fun setPluginHelper(helper: PluginsHelper?) {
pluginsHelper = WeakReference(helper)
}
fun getPluginHelper() = pluginsHelper?.get()
}
sweetModelPatch: 这个必须有
val intent =Intent(this, TestActivity::class.java)
intent.putExtra("sweetModelPatch", GlobalPluginConfig.getPluginHelper()?.pluginsApkPath)
startActivity(intent)abstract class BaseActivity:Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
//注入插件资源
GlobalPluginConfig.getPluginHelper()?.injectPluginAppResources(this)
super.onCreate(savedInstanceState)
}
override fun startActivity(intent: Intent?) {
//添加sweetModelPatch
intent?.putExtra("sweetModelPatch",GlobalPluginConfig.getPluginHelper()?.pluginsApkPath)
super.startActivity(intent)
}
}PluginsUtils.getWxClassLoader() : 获取最上层宿主ClassLoader
PluginsUtils.getWxApplication() : 获取最上层宿主ApplicatioCoreStorage.getWxId() : 获取微信号
CoreStorage.getWxOldId() : 获取原始微信号
CoreStorage.getPhone() : 获取手机号
CoreStorage.getSex() : 获取性别
CoreStorage.getNickName() : 获取昵称
CoreStorage.getSign() : 获取个性签名AvatarStorage.setAvatar() : ImageView 设置头像
AvatarStorage.getAvatar() : 获取头像
AvatarStorage.getAvatar() : 获取头像MsgTools.sendTextMsg : 发送文本消息HttpUtils.get() : GET请求
HttpUtils.post() : POST请求
HttpUtils.submitForm() : 表单提交
HttpUtils.download() : 文件下载LogKTX.e() : 日志打印
LogKTX.eStack() : 打印日志调用栈scope {
HttpUtils.get<String>("").onSuccess { }.onFailure { }
}File.smartCreateNewFile() : 创建新文件
File.smartCreateFolder() : 创建文件夹
File.deleteFolder() : 删除文件夹
File.md5() : 获取文件MD5