首页 > 其他 > 详细

hook原生打包流程

时间:2019-08-02 21:15:16      阅读:85      评论:0      收藏:0      [点我收藏+]

将实际执行的Transform换成了MatrixTraceTransform

public static void inject(Project project, def variant) {
//获取Matrix trace的gradle配置参数
def configuration = project.matrix.trace
//hook的Task名
String hackTransformTaskName = getTransformTaskName(
configuration.hasProperty(‘customDexTransformName‘) ? configuration.customDexTransformName : "",
"",variant.name
)
//同上
String hackTransformTaskNameForWrapper = getTransformTaskName(
configuration.hasProperty(‘customDexTransformName‘) ? configuration.customDexTransformName : "",
"Builder",variant.name
)

project.logger.info("prepare inject dex transform :" + hackTransformTaskName +" hackTransformTaskNameForWrapper:"+hackTransformTaskNameForWrapper)

project.getGradle().getTaskGraph().addTaskExecutionGraphListener(new TaskExecutionGraphListener() {
@Override
public void graphPopulated(TaskExecutionGraph taskGraph) {
for (Task task : taskGraph.getAllTasks()) {
//找到需要hook的Task名称
if ((task.name.equalsIgnoreCase(hackTransformTaskName) || task.name.equalsIgnoreCase(hackTransformTaskNameForWrapper))
&& !(((TransformTask) task).getTransform() instanceof MatrixTraceTransform)) {
project.logger.warn("find dex transform. transform class: " + task.transform.getClass() + " . task name: " + task.name)
project.logger.info("variant name: " + variant.name)
Field field = TransformTask.class.getDeclaredField("transform")
field.setAccessible(true)
//反射替换成MatrixTraceTransform,并将原transform传入,最后执行原transform逻辑
field.set(task, new MatrixTraceTransform(project, variant, task.transform))
project.logger.warn("transform class after hook: " + task.transform.getClass())
break
}
}
}
})

hook原生打包流程

原文:https://www.cnblogs.com/ly570/p/11291180.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!