库依赖会增加 APK 的大小吗? [英] Do library dependency increase size of APK?

查看:29
本文介绍了库依赖会增加 APK 的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有多个库,例如

I have multiple libraries in my project like

dependencies {
    compile files('libs/universalloaderlibrary.jar')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    //noinspection GradleCompatible
    compile 'com.google.android.gms:play-services-gcm:7.3.0'
    compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.loopj.android:android-async-http:1.4.8'
    compile 'com.android.support:multidex:1.0.1'
}

和其他库.他们是否过多地增加了应用程序的大小.我的项目中有超过 25 个库.现在 APK 大小为 11 MB,我必须在其中添加更多功能.可能是什么原因?

and other libraries. Do they increase app size too much. I have more than 25 libraries in my project. Right now APK size is 11 MB and i have to add more functionalities in that. What could be the reason?

关于这个,我有一些问题.

I have some questions, regarding this.

什么需要更多内存?

  1. 在项目中添加了模块.
  2. 文件添加为 JAR 文件.
  3. 我们添加的 Gradle 依赖就像 compile 'com.android.support:appcompat-v7:22.2.1'.

我读过通过启用 Proguard ,将 minifyEnabled 设置为 true 可以减少应用程序大小.

I have read that by Enabling Proguard , setting minifyEnabled true can reduce app size.

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

他们在图片背后是如何工作的?

How do they work behind the picture ?

我们应该避免在项目中使用多个库吗?

Should we avoid to use multiple libraries in project ?

我心中有很多关于减少 APK 大小的问题.任何形式的建议和帮助将是可观的.提前致谢.

Lots of questions are in my mind for reducing APK size. Any kind of suggestion and help would be appreciable. Thanks in Advance.

推荐答案

所有这三种方法都会增加 APK 的大小.它们之间的区别在于源代码驻留在何处:

All three of those methods will increase the size of your APK. The difference between them is where does the source code reside:

  • 模块依赖是本地机器上的源代码.在您构建应用程序时,它会被编译为字节码.
  • JAR 文件是预编译的字节码.它也在你的本地机器上,但它并不是真正的源代码.字节码只是在您构建时添加到您自己的.
  • Gradle 依赖项与使用 JAR 文件基本相同,不同之处在于 Gradle 会下载预编译的工件,而不是将其作为文件添加到本地机器上.

不管上述情况,依赖项将其类贡献给构建,它们将出现在最终输出(APK)中.

Regardless of the above, the dependency contributes its classes to the build and they will be present in the final output (the APK).

Proguard 做了一些可以减小 APK 大小的事情.它可以静态分析所有字节码并删除从未使用过的类和方法.它还可以将类、字段和方法重命名为更小的标识符,如abc",这可能会在一定程度上缩小字节码的大小.

Proguard does a few things that can reduce the size of your APK. It can statically analyze all the bytecode and remove classes and methods that are never used. It also can rename classes, fields, and methods to smaller identifiers like "abc", which may shrink the size of the bytecode somewhat.

这篇关于库依赖会增加 APK 的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆