YadirHB YadirHB - 1 month ago 13
Java Question

Using proguard in java modules Android Studio

I'm attempting to use proguard in a build.gradle file for a java module on Android Studio and I need to ofuscate the resulting source code but when I use proguard as I used to in other projects the build task fails. Below I show what I've trying to do and the error:

import proguard.gradle.ProGuardTask

apply plugin: 'java'

task proguardFiles(dependsOn: compileJava, type: ProGuardTask) {

Error:Cause: startup failed:
script '...Path\build.gradle': 1: unable to resolve class proguard.gradle.ProGuardTask
@ line 1, column 1.
import proguard.gradle.ProGuardTask

1 error

Any ideas about the solution?


I found the solution to my own question, I hope this be helpful for someone who need it.

Include at top of gradle file:

import proguard.gradle.ProGuardTask

in other place into the same file or project configuration (gradle file) put this:

buildscript {
    repositories {

    dependencies {
        classpath 'net.sf.proguard:proguard-gradle:5.2.1'

finally define your custom proguardTask:

task proguardFiles(type: ProGuardTask, dependsOn: compileJava) {
    printmapping "$buildDir/outputs/mapping/mapping.txt"
    configuration 'proguard-rules.pro'

    libraryjars files(configurations.compile.findAll {}.collect())

    injars sourceSets.main.output

    outjars "$buildDir/libs/myJarName-${version}.jar"

and it should work!!!