Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

click-debounce

> 包管理
Open source

Using ASM to handle Android's click debounce, specially a quick double click.

192 stars0 likes1 views
WebsiteGitHub

About

Using ASM to handle Android's click debounce, specially a quick double click.

README.md

click-debounce

Support incremental compilation! Support parallel compilation! Faster compilation speed, and shorter compilation time.

It is a gradle plugin that uses bytecode weaving technology to solve the click jitter problem of Android applications.

For example, a normal onClick method without any debounce plan, multiple quick clicks may trigger multiple Activity starts:

java
  @Override public void onClick(View v) {
    startActivity(new Intent(MainActivity.this, SecondActivity.class));
  }

modify the bytecode at compile time to:

java
  @Debounced
  public void onClick(View var1) {
    if (DebouncedPredictor.shouldDoClick(var1)) {
      startActivity(new Intent(this, SecondActivity.class));
    }
  }

The @Debounced annotation indicates that the method has been debounced. The shouldDoClick(View) method will determine which are the jitters and which are the correct clicks.

I also wrote a BLOG to share my ideas to solve the click jitter.

Note: This repository is just a gradle plugin, responsible for bytecode weaving work. Android runtime library please move here.

Requirements

  • JDK 1.7 +
  • Gradle 4.0.0 +

To build

bash

$ git clone [email protected]:SmartDengg/asm-clickdebounce.git
$ cd asm-clickdebounce/
$ ./gradlew build

Getting Started

Step 1. Add the JitPack repository and the plugin to your buildscript:

groovy

buildscript {

    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        ...
        classpath 'com.github.SmartDengg.click-debounce:click-debounce-gradle-plugin:2.1.0'
    }
}

Step 2. Apply it in your module:

Supports com.android.application, com.android.library and com.android.feature.

groovy

apply plugin: 'smartdengg.clickdebounce'
// or apply plugin: 'clickdebounce'

Step 3 (Optional). By adding the following code to your build.gradle to enable printe the beautiful log or add an exclusive list to indicate which methods do not need to be debounced. By default, the log is not printed, and process all the methods in the support list.

It is not recommended to manually add @Debounce annotations to methods, you should use the exclusive feature that which methods should not be debounced, as follows:

groovy

debounce {
  // enable log
  loggable = true
  // java bytecode descriptor: [class: [methods]]
  exclusion = ["com/smartdengg/clickdebounce/ClickProxy": ['onClick(Landroid/view/View;)V',
                                                           'onItemClick(Landroid/widget/AdapterView;Landroid/view/View;IJ)V']]
}

Step 4 (Optional). Set the debounce window time in your Java code(default is 300 milliseconds):

java

DebouncedPredictor.FROZEN_WINDOW_MILLIS = 400L

Artifact

We output some log files to help developers better understand the build information. These file path is located in buildDir/outputs/debounce/logs//, as follows:

.
+-- app (apply this AGP)
|   +-- build
|       +-- generated
|       +-- intermediates
|       +-- outputs
|           +-- debounce
|               +-- logs
|                   +-- debug
|                       +-- files.txt
|                       +-- classes.txt
+-- build.gradle
+-- gradle.properties
+-- gradlew
+-- gradlew.bat
+-- settings.gradle
  • files.txt :Record the class files consumed by this build,it can help you better understand this build.
  • classes.txt :Record information about the classes and methods woven in this build.

How it works

Will not intercept the touch event delivery, only intercepted in the callback of the click event, so that it will not be passed to the business logic.

Support

  • View.OnClickListener
  • AdapterView.OnItemClickListener

R8 / ProGuard (Not Required)

Pure bytecode weaving without any reflections. No Proguard rules are required.

Bugs and Feedback

For bugs, feature requests, and discussion please use GitHub Issues. Or send email to [email protected].

Found this project useful

:heart: Hope this article can help you. Support by clicking the :star:, or share it with people around you. :heart:

About me

email : [email protected]

blog : 小鄧子

weibo : -小鄧子-

License

See the LICENSE file for license rights and limitations (MIT).

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroidaopaop-pluginasm

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image