库依赖增加APK的大小?

Anu*_*rma 5 android apk android-library android-gradle-plugin android-proguard

我的项目中有多个库

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'
}
Run Code Online (Sandbox Code Playgroud)

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

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

什么需要更多的记忆?

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

我已经读过,通过启用Proguard,设置为minifyEnabledtrue可以减少应用程序的大小.

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

他们如何在图片后面工作?

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

我想到了很多减少APK大小的问题.任何建议和帮助都会很明显.提前致谢.

Kar*_*uri 11

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

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

无论如何,依赖关系都会将其类贡献给构建,并且它们将出现在最终输出(APK)中.

Proguard做了一些可以减小APK大小的东西.它可以静态分析所有字节码,并删除从未使用过的类和方法.它还可以将类,字段和方法重命名为较小的标识符,如"abc",这可能会稍微缩小字节码的大小.