Does adding dependency to gradle in android studio while not using it at all affect apk size?

1.3k Views Asked by At

In a big project while former developers already worked on, you can find dependencies in gradle that doesn't have any usages at all.

Do those dependencies affect apk size? and how dependencies affect apk size, what if you're just using one method from a library, does this mean that all the library files attached to your apk.

3

There are 3 best solutions below

2
On BEST ANSWER

Yes, unused dependencies do increase the apk size.

Enabling

minifyEnabled true

can analyze all the bytecode and remove unused classes and methods.

buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      shrinkResources true
    }
  }

It is good to remove all the unused dependencies from gradle

4
On

Yes gradle dependency definitely affects your apk size. if you are not using gradle dependency anywhere in the project then please remove the dependency

And even if you are using one mehtod from a library all files are attached to your apk. so to avoid this enable proguard tool with shrinkResource as true. This will obfuscate and simply remove unused method in the library and reduce the apk size

1
On

Do those dependencies affect apk size? and how dependencies affect apk size

Yes of course.
The dependencies are added in the final apk, so the classes and the resources are added and they increase the size of the apk.

what if you're just using one method from a library, does this mean that all the library files attached to your apk.

Yes, all the library is attached.

There are some features in gradle to add a dependency removing the unused resources.