Skip to content Skip to sidebar Skip to footer

Does Adding Dependency To Gradle In Android Studio While Not Using It At All Affect Apk Size?

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

Solution 1:

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

Solution 2:

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.

Solution 3:

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

Post a Comment for "Does Adding Dependency To Gradle In Android Studio While Not Using It At All Affect Apk Size?"