enable proguard only for remove unused code

6.4k Views Asked by At

My app using some jar libs with too many methods, but in fact used only 2-3 methods from this libs. Total size of this libs more than 2Mb. I don't need all of it and i want to shrink my apk with ProGuard.

I need to enable ProGuard and configure it only for remove unused code and shrink apk size. but I don't know how. I don't want to obfuscate my app and etc. only shrink final size.

I try to enable proguard by

minifyEnabled true

but it got only errors and nothing.

1

There are 1 best solutions below

0
On

To only shrink your application you should do the following:

release {
  proguardFile getDefaultProguardFile('proguard-android.txt')
  proguardFile 'proguard-shrink-only.txt'
  proguardFile 'proguard-project.txt'
}

The proguard-shrink-only.txt should contain the following options:

-dontobfuscate
-dontoptimize

The proguard-project.txt should contain your project specific keep rules that might be needed for classes that are used via reflection.