Skip to content

A gradle plugin that generate for android library.


Notifications You must be signed in to change notification settings


Repository files navigation


R2generator is a gradle plugin that generate for android library.


Inside android library, we usually usegetResources().getIdentifier("res_name", "res_type", "package_name")to access resources.

This plugin provide an easier way to handle the "res_name" above by generating file during build time.

Here's a sample of auto generated :

public final class R2 {
  public static final class anim {
    public static final String abc_fade_in = "abc_fade_in";

After applying this gradle plugin, you can simply use R2.anim.abc_fade_in to replace your hardcoded "abc_fade_in".

If you take a look at the source code, you may find out that this library is nothing but a Butterknife Library project copycat. But it does make some difference : ) .


Add this to your bulidscript:

buildscript {
    repositories {
        maven { url '' }
    dependencies {
        classpath 'com.github.nichbar:r2generator:1.0.5'

then apply it in your module:

apply plugin: 'r2generator-plugin'


If you wanna modify this plugin, you may follow these procedure.

  1. Clone this project.
  2. Remove maven { url '' } from root build.gradle file.
  3. Apply your changes to r2generator library.
  4. Execute ./gradlew publish to generate plugin.
  5. Run the demo project to check your changes.