Generating jar files using progaurd in gradle android build

526 Views Asked by At

Usually by providing -injars and -outjars to progaurd , we can generate obfuscated jar file of filtered classes from -injars.

is there any way in gradle android build by using proguardFile attribute, to generated obfuscated jar file of filtered classes from group of project classes . These filtered jar files are in addition to gradle android build binary.

2

There are 2 best solutions below

0
Shanker On BEST ANSWER

My requirement of generating individual obfuscated jar files based on few selected class files from single library project is achieved with below way. These individual jar files are in addition to final android binary i.e, .aar file.

Debug : 1. During android build, gradle moves all the compiled java files to /build/intermediates/javac/debug/compileDebugJavaWithJavac/classes folder.

  1. In proguard file I have given -injars as above folder and -outjars as my custom path with filters.

  2. Using 'proguardFile' attribute I have passed proguard file to build.gradle

  3. All the individual jar files specified using -injars and -outjars would be obfuscated and will be placed in -outjars path

Eg :

In debug mode :

-injars 'D:\projectname\build\intermediates\javac\debug\compileDebugJavaWithJavac\classes'(**.class)

-outjars 'D:\projectname\build\intermediates\transforms\proguard\debug\1.jar'(com/ui/tab/TabWidget.class,com/ui/Tab.class)

-injars 'D:\projectname\build\intermediates\javac\debug\compileDebugJavaWithJavac\classes'(**.class)

-outjars 'D:\projectname\build\intermediates\transforms\proguard\debug\1.jar'(com/ui/CollapsibleWidget.class)

0
Bakon Jarser On

You will probably have to create a new library module in your project and refactor your code to move the classes you want in the jar into the new library module.

See this answer: https://stackoverflow.com/a/47444948/3501286

and this one: https://stackoverflow.com/a/19037807/3501286