Inline constant fields of android R class by asm and transform-api
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
shrinker
test
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
publish.gradle
settings.gradle

README.md

Shrinker

Shrinker will remove all R.class and R$**.class and all constant integer fields will be inlined by asm and transform-api.

I have post more details on my own blog (in Chinese), click here to check it out.

Usage

version You can get shrinker from jitpack

To apply shrinker to your android application:

Step1. Add it in your buildscript section of app's build.gradle

buildscript {
    repositories {
        //...
        maven { url 'https://jitpack.io' }
    }

    dependencies {
        classpath 'net.yrom:shrinker:0.2.9'
    }
}

Step2. Apply it after the Android plugin

apply plugin: 'com.android.application'
//...
apply plugin: 'net.yrom.shrinker'

NOTE that shrinker plugin requires android gradle build tools version at least 3.0.0 and it will be disabled if run in debug build.

Show case

There is a small test application which depends on so many support libraries, would show how many fields shrinked.

Run with shrinker:

./gradlew :test:assembleRelease -PENABLE_SHRINKER

Run with removeUnusedCode:

android {
    buildTypes {
        release {
            ...
            postprocessing {
                removeUnusedCode = true
            }
        }
    }
    ...
}

Content below counts by dexcount-gradle-plugin

options methods fields classes
origin 22164 14367 2563
shrinker 21979 7805 2392
removeUnusedCode 11338 6655 1296
shrinker & removeUnusedCode 11335 3302 1274

License

Copyright 2017 Yrom

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.