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

查看:223
本文介绍了库依赖性会增加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?

对此我有一些疑问.

什么需要更多的内存?

What takes more memory ?

  1. 已在项目中添加模块.
  2. 文件已添加为JAR文件.
  3. 我们添加了等级依赖性,就像compile 'com.android.support:appcompat-v7:22.2.1'一样.
  1. Module Added in project.
  2. File added as JAR file.
  3. Gradle Dependency we add just like 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天全站免登陆