GithubHelp home page GithubHelp logo

thinannotation's Introduction

相关文章链接:MainDex 优化记

原理

此插件只作用于打包过程,编码过程无感知、无影响。

混淆之后将会产生一个包含应用中所有 class 的 jar,通过 ASM 扫描所有的类、类的方法、类的字段等一切可能会出现注解的地方,扫描到开发者配置的注解则将其删除;而如果当前类是注解类且是开发者所配置的类的话,该注解类将会被删除。

配置

thinAnnotation 默认删除所有的 SOURCE 时期注解,因为使用 SOURCE 时期注解的地方实际上会在 .java -> .class 过程中被擦除,所以所有的 SOURCE 注解类实际上都是无用类,例如 android/support/design/widget/TabLayout$Mode 类;thinAnnotation 默认删除了 butterknife/ 包、 android/support/annotation/ 包、androidx/annotation/ 包的所有注解,原因是这些 CLASS 时期的类在运行时是无用的(除非特殊要求,CLASS 文件实际上也是可以全部删除的);开发者只需要配置想要删除的 CLASS 和 RUNTIME 时期的注解类,配置方式如下——

在 project/build.gradle 中:

buildscript {
  repositories {
    maven { url 'https://jitpack.io' }
  }
  dependencies {
    classpath 'com.github.jokermonn:thinAnnotation:0.0.2'
  }
}

在 app/build.gradle 中:

apply plugin: 'thinAnnotation'

thinAnnotation {
  enable true
  shrinkClass 'com/joker/maindexkeep/annotations/RuntimeAnn'
  // 删除 com/joker/maindexkeep/shrink/ 下所有注解
  shrinkPackage('com/joker/maindexkeep/shrink/', { true })
  // 删除 com/joker/maindexkeep/shrink2/ 下除 RUNTIME 之外的所有注解
  shrinkPackage 'com/joker/maindexkeep/shrink2/'
}

日志在:app/build/outputs/thinAnnotation 路径下。

示例

以 butterknife 为例:

使用前:butterknife 包注解类存在,@BindView 等注解存在于 .class 文件中

使用后:butterknife 包注解类全部删除,所有使用该注解的地方也都会被清除注解

CHANGELOG

0.0.3:

  • fix issue#1
  • 使用方式稍作改变
  • 丰富 thinAnnotation log
  • 使用 kotlin
  • 增加对 org/intellij/lang/annotations/org/jetbrains/annotations/ 的注解类删除

thinannotation's People

Contributors

jokermonn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

msdgwzhy6 devenlu

thinannotation's Issues

Could not find method execute()

Could not find method execute() for arguments [] on task ':app:thinAnnotationForBetaRelease' of type com.joker.buildsrc.ThinAnnotationTask.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.