EventBus3.0 混淆解决方案

EventBus 3.0采用注解处理,为了提高效率可在编译时通过注解处理器生成索引代码。 但是如果使用索引的话就不能混淆被Subscribe注解的方法。 为了能够提高效率使用索引并且混淆被Subscribe注解的方法可以使_gradle.plugin.greenrobot.eventbus_插件

[TOC]

gradle.plugin.greenrobot.eventbus

JitPack

gradle.plugin.greenrobot.eventbus is a gradle plugin for EventBus when use proguard.

Process

1. hook gradle proguard task.

2. parse mapping.txt.

3. analyse class file.

4. replace method name.

Integration

How to use

1. integration EventBus and EventBusAnnotationProcessor

2. add the jitpack repository and plugin dependency to your project build file

1buildscript { 2 repositories { 3 jcenter() 4 maven { url "https://jitpack.io" } 5 } 6 dependencies { 7 classpath 'com.github.JackyAnn:gradle.plugin.greenrobot.eventbus:v1.0' 8 } 9}

3. apply plugin to you module build file

apply plugin: 'com.tobelinker.greenrobot.eventbus'

Sample

gradle.plugin.greenrobot.eventbus.sample

  • source code generate by EventBusAnnotationProcessor

    package com.sample.index;

    import org.greenrobot.eventbus.meta.SimpleSubscriberInfo; import org.greenrobot.eventbus.meta.SubscriberMethodInfo; import org.greenrobot.eventbus.meta.SubscriberInfo; import org.greenrobot.eventbus.meta.SubscriberInfoIndex;

    import org.greenrobot.eventbus.ThreadMode;

    import java.util.HashMap; import java.util.Map;

    /** This class is generated by EventBus, do not edit. */ public class BusIndex implements SubscriberInfoIndex { private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;

    1static { 2 SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>(); 3 4 putIndex(new SimpleSubscriberInfo(com.tobelinker.greenrobot.eventbus.sample.BaseActivity.class, true, 5 new SubscriberMethodInfo[] { 6 new SubscriberMethodInfo("showMessage", com.tobelinker.greenrobot.eventbus.sample.Message.class), 7 new SubscriberMethodInfo("showMessage", com.tobelinker.greenrobot.eventbus.sample.EventMessage.class), 8 })); 9 10 putIndex(new SimpleSubscriberInfo(com.tobelinker.greenrobot.eventbus.sample.MainActivity.class, true, 11 new SubscriberMethodInfo[] { 12 new SubscriberMethodInfo("showMessage", com.tobelinker.greenrobot.eventbus.sample.Message.class), 13 new SubscriberMethodInfo("showMessage", com.tobelinker.greenrobot.eventbus.sample.EventMessage.class), 14 new SubscriberMethodInfo("showMessage", String.class), 15 new SubscriberMethodInfo("showMessage", Object.class), 16 })); 17 18} 19 20private static void putIndex(SubscriberInfo info) { 21 SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info); 22} 23 24@Override 25public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) { 26 SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass); 27 if (info != null) { 28 return info; 29 } else { 30 return null; 31 } 32}

    }

  • compiled code whith proguard

    package com.a.a;

    import java.util.; import a.a.a.a.; import com.tobelinker.greenrobot.eventbus.sample.*;

    public class a implements d { private static final Map<Class<?>, c> a;

    1private static void a(final c c) { 2 com.a.a.a.a.put(c.a(), c); 3} 4 5@Override 6public c a(final Class<?> clazz) { 7 final c c = com.a.a.a.a.get(clazz); 8 if (c != null) { 9 return c; 10 } 11 return null; 12} 13 14static { 15 a = new HashMap<Class<?>, c>(); 16 a(new a.a.a.a.b(com.tobelinker.greenrobot.eventbus.sample.a.class, true, new e[] { new e("showMessage", com.tobelinker.greenrobot.eventbus.sample.c.class), new e("showMessage", b.class) })); 17 a(new a.a.a.a.b(MainActivity.class, true, new e[] { new e("showMessage", com.tobelinker.greenrobot.eventbus.sample.c.class), new e("showMessage", b.class), new e("showMessage", String.class), new e("showMessage", Object.class) })); 18}

    }

  • the mapping.txt

    com.sample.index.BusIndex -> com.a.a.a: java.util.Map SUBSCRIBER_INDEX -> a void <init>() -> <init> void putIndex(org.greenrobot.eventbus.meta.SubscriberInfo) -> a org.greenrobot.eventbus.meta.SubscriberInfo getSubscriberInfo(java.lang.Class) -> a void <clinit>() -> <clinit> com.tobelinker.greenrobot.eventbus.sample.BaseActivity -> com.tobelinker.greenrobot.eventbus.sample.a: void <init>() -> <init> void showMessage(com.tobelinker.greenrobot.eventbus.sample.Message) -> a void showMessage(com.tobelinker.greenrobot.eventbus.sample.EventMessage) -> a com.tobelinker.greenrobot.eventbus.sample.EventMessage -> com.tobelinker.greenrobot.eventbus.sample.b: java.lang.String message -> a void <init>(java.lang.String) -> <init> java.lang.String toString() -> toString com.tobelinker.greenrobot.eventbus.sample.MainActivity -> com.tobelinker.greenrobot.eventbus.sample.MainActivity: org.greenrobot.eventbus.EventBus eventBus -> a void <init>() -> <init> void onCreate(android.os.Bundle) -> onCreate void onDestroy() -> onDestroy void showMessage(com.tobelinker.greenrobot.eventbus.sample.Message) -> a void showMessage(com.tobelinker.greenrobot.eventbus.sample.EventMessage) -> a void showMessage(java.lang.String) -> a com.tobelinker.greenrobot.eventbus.sample.Message -> com.tobelinker.greenrobot.eventbus.sample.c: java.lang.String message -> a void <init>(java.lang.String) -> <init> java.lang.String toString() -> toString

  • the final code after processed

    package com.a.a;

    import java.util.; import a.a.a.a.; import com.tobelinker.greenrobot.eventbus.sample.*;

    public class a implements d { private static final Map<Class<?>, c> a;

    1private static void a(final c c) { 2 com.a.a.a.a.put(c.a(), c); 3} 4 5@Override 6public c a(final Class<?> clazz) { 7 final c c = com.a.a.a.a.get(clazz); 8 if (c != null) { 9 return c; 10 } 11 return null; 12} 13 14static { 15 a = new HashMap<Class<?>, c>(); 16 a(new a.a.a.a.b(com.tobelinker.greenrobot.eventbus.sample.a.class, true, new e[] { new e("a", com.tobelinker.greenrobot.eventbus.sample.c.class), new e("a", b.class) })); 17 a(new a.a.a.a.b(MainActivity.class, true, new e[] { new e("a", com.tobelinker.greenrobot.eventbus.sample.c.class), new e("a", b.class), new e("a", String.class), new e("showMessage", Object.class) })); 18}

    }

Notice

none

License

Apache License, Version 2.0

Copyright (c) 2016, tobelinker.com

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

distinct效率更高还是group by效率更高?

目录00结论01distinct的使用02groupby的使用03distinct和groupby原理04推荐groupby的原因00结论先说大致的结论(完整结论在文末):在语义相同,有索引的情况下groupby和distinct都能使用索引,效率相同。在语义相同,无索引的情况下:distinct效率高于groupby。原因是di

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )