xiaonia / proguard-1

ProGuard, Java optimizer and obfuscator

Home Page:https://www.guardsquare.com/en/products/proguard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



ProGuard

jcenter


Quick Start β€’ Features β€’ Contributing β€’ License


ProGuard is a free shrinker, optimizer, obfuscator, and preverifier for Java bytecode:

  • It detects and removes unused classes, fields, methods, and attributes.

  • It optimizes bytecode and removes unused instructions.

  • It renames the remaining classes, fields, and methods using short meaningless names.

The resulting applications and libraries are smaller, faster, and a bit better hardened against reverse engineering. ProGuard is very popular for Android development, but it also works for Java code in general.

πŸš€ Quick Start

ProGuard is integrated in Google's Android SDK. If you have an Android Gradle project you can enable ProGuard instead of the default R8 compiler:

  1. Disable R8 in your gradle.properties:

    android.enableR8=false
    android.enableR8.libraries=false
    
  2. Override the default version of ProGuard with the most recent one in your main build.gradle:

    buildscript {
        ...
        configurations.all {
            resolutionStrategy {
                dependencySubstitution {
                    substitute module('net.sf.proguard:proguard-gradle') with module('com.guardsquare:proguard-gradle:7.0.0')
                }
            }
        }
    }
    
  3. Enable minification as usual in your build.gradle:

    android {
        ...
        buildTypes {
            release {
                minifyEnabled   true
                shrinkResources true
                proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
                proguardFile 'proguard-project.txt'
            }
        }
    }
    
  4. Add any necessary configuration to your proguard-project.txt.

You can then build your application as usual:

gradle assembleRelease

The repository contains some sample configurations in the examples directory. Notably, examples/android has a small working Android project.

✨ Features

ProGuard works like an advanced optimizing compiler, removing unused classes, fields, methods, and attributes, shortening identifiers, merging classes, inlining methods, propagating constants, removing unused parameters, etc.

  • The optimizations typically reduce the size of an application by anything between 20% and 90%. The reduction mostly depends on the size of external libraries that ProGuard can remove in whole or in part.

  • The optimizations may also improve the performance of the application, by up to 20%. For Java virtual machines on servers and desktops, the difference generally isn't noticeable. For the Dalvik virtual machine and ART on Android devices, the difference can be worth it.

  • ProGuard can also remove logging code, from applications and their libraries, without needing to change the source code β€” in fact, without needing the source code at all!

The manual pages (markdown, html) cover the features and usage of ProGuard in detail.

🀝 Contributing

ProGuard builds on the ProGuard Core library.

Contributions, issues and feature requests are welcome in both projects. Feel free to check the issues page and the contributing guide if you would like to contribute.

πŸ“ License

Copyright (c) 2002-2020 Guardsquare NV. ProGuard is released under the GNU General Public License, version 2, with exceptions granted to a number of projects.

About

ProGuard, Java optimizer and obfuscator

https://www.guardsquare.com/en/products/proguard

License:GNU General Public License v2.0


Languages

Language:Java 98.8%Language:Groovy 1.0%Language:Shell 0.1%Language:Batchfile 0.0%Language:HTML 0.0%