我的项目中有多个库,如
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,我必须添加更多的功能。 可能是什么原因?
我对此有一些疑问。
什么需要更多记忆?
compile 'com.android.support:appcompat-v7:22.2.1'
。我已阅读通过启用Proguard
,设置minifyEnabled
为true可以减少应用程序大小。
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
他们如何在图片后面工作?
我们应该避免在项目中使用多个库吗?
我想到了很多减少APK尺寸的问题。 任何建议和帮助都会很明显。 在此先感谢。
答案 0 :(得分:8)
所有这三种方法都会增加APK的大小。它们之间的区别在于源代码所在的位置:
无论如何,依赖关系都会将其类贡献给构建,并且它们将出现在最终输出(APK)中。
Proguard做了一些可以减小APK大小的东西。它可以静态分析所有字节码,并删除从未使用过的类和方法。它还可以将类,字段和方法重命名为较小的标识符,如“abc”,这可能会稍微缩小字节码的大小。
答案 1 :(得分:2)
是的,依赖项加上项目自己的源代码编译的输出,被发送到dex进行字节码转换并包含在最终的APK中。
使用proguard,可以系统地删除未使用的类