1

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.

Shanker
  • 864
  • 6
  • 24
  • just configure proguard to obfuscate that library module. – Martin Zeitler Apr 25 '19 at 08:15
  • what value to give for -injars ? As per progaurd documentation, we can give aars, wars, ears, zips, apks, directories as input for -injars, but when I give \build\intermediates\javac\release\compileReleaseJavaWithJavac\classes as input, it fails with below error --> Warning: Exception while processing task java.io.IOException: The same input jar [D:\Luavmandroid\luavmandroid\build\intermediates\javac\release\compileReleaseJavaWithJavac\classes] is specified twice. – Shanker Apr 25 '19 at 08:45
  • 1
    just don't use `-injars` ... and don't define paths which are on the default class-path. obfuscating a library module works no different than obfuscating an application module. – Martin Zeitler Apr 25 '19 at 09:10
  • ok from your above point I understood that classes will be picked from default class-path. My requirement is to select few classes and then pack into separate jar file in addition to final gradle android build binary. – Shanker Apr 25 '19 at 09:36

2 Answers2

0

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

Bakon Jarser
  • 703
  • 6
  • 20
0

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)

Shanker
  • 864
  • 6
  • 24