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

天大地大妈咪最大 提交于 2019-12-23 16:24:52

问题


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.


回答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




回答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.




回答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



来源:https://stackoverflow.com/questions/41221828/does-adding-dependency-to-gradle-in-android-studio-while-not-using-it-at-all-aff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!