16

Hi I developed one android library and Now I want to obfuscate it for redistribution. I develop my library with eclipse and android version 4.1.2. I tried obfuscating with eclipse and pro-guard. I do export and and also put proguard.config = proguard-project.text in project-properties but it not generating any jar file. It shows me result as its not allowing to library projects.

So I don't know how to obfuscating android library project. I need help regarding how to obfuscating of android library projects.

Need Help Thank you.

nilkash
  • 7,408
  • 32
  • 99
  • 176

2 Answers2

29

The Android SDK doesn't apply ProGuard to library projects; it only applies ProGuard to final applications (including their libraries). The latter is more effective in terms of shrinking, optimization, and obfuscation, because it can work on a larger body of code and it doesn't need to preserve the public API of the libraries.

If you want to distribute your library as an end-product, you can post-process it, as discussed in the ProGuard manual > Examples > A typical library.

Alternatively, DexGuard, ProGuard's commercial sibling for Android, can also process library projects out of the box.

(I am the developer of ProGuard and DexGuard)

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • 2
    does that site work properly for you? Every time I try to click Manual > Examples it redirects me to the home/main page of the site. Also - thanks for all the work on ProGuard. Great tool. – Eggman87 Jul 30 '13 at 00:45
  • @Eggman87 The updated web pages for ProGuard version 4.10 didn't work well in Chrome. I've now fixed them. Make sure you clean your cache. Note that the documentation is also included in the ProGuard distribution. – Eric Lafortune Jul 31 '13 at 08:34
  • Thanks @Eric Lafortune . It is now working, thanks for noting the docs in the distro. – Eggman87 Aug 05 '13 at 02:29
  • The direct link above still does not work for me (Google Chrome 33.0.1750.146 on Mac OS X). Just click the "Examples" link under Limitations and then "a typical library" to go the correct example. – runamok Apr 01 '14 at 17:22
  • 3
    Can someone share gradle configuration for a module to be exported as a proguarded library? – inder Feb 12 '15 at 21:51
  • 4
    I think they now support proguard for aar project (library project) by simply specify `minifyEnabled true` in build.gradle (AS2.3.1+buildToolsVersion "25.0.2") – bj4947 Apr 17 '17 at 18:05
  • @IHC_Applroid, I think enabling minifyEnabled true worked for me. But now I can't access any class from the aar file. We may need to exclude the public classes and public members of the library. – Ashutosh Chamoli Apr 01 '18 at 07:52
  • @EricLafortune The suggested rules for "typical library" are to keep everything from the public classes of the library. That means all privates and internals in the public classes are NOT obfuscated. That's not quite good for protecting proprietary code. And I believe nowadays R8 (and probably Proguard too) respect "minifyEnabled" true for library modules. – WindRider Mar 29 '21 at 10:49
1

In order to obfuscate your library what you need to do is:

  1. Make sure gradle settings for lib module state minifyEnabled true .

  2. run ./gradlew assemble{flavor}Release

LocoGris
  • 4,432
  • 3
  • 15
  • 30
Oren K.
  • 97
  • 1
  • 10