【发布时间】:2015-12-06 03:50:42
【问题描述】:
我有自己的自定义库,用于维护我想在多个项目中使用的方法和类。它没有编译成 .jar 文件 - 它设置为 com.android.library 并位于其自己的文件夹中。
我的一个应用程序非常小 - 不到 500k。当我添加这个库时,它激增到 1350k。尽管它仍然很小,但这对于这个特定的应用程序来说是一个问题,我已承诺尽可能小。
应用程序本身的 src 文件夹为 77k。库项目的 src 文件夹为 112k。生成的 apk 的 .dex 文件正好是 1mb。 这怎么可能?
图书馆项目确实引用了 play-services-vision。但是这个应用程序中没有引用它,我相信 Proguard 应该把它去掉。
在“构建变体”窗口中,应用和库都设置为“发布”。
我的应用的 build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
//**CONFIG STUFF**//
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
applicationIdSuffix '.debug'
versionNameSuffix '.debug'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile project(':farmsoftlibs')
}
注意:appcompat 引用也在我的应用程序的旧版本中,即 500k,所以我知道这不是罪魁祸首。
我的图书馆的 build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-vision:7.8.0'
}
所以我认为可能解决这个难题的问题是:
- 我的 apk 比应用程序和库的完整 java 和 res 文件夹的总和大多少,尤其是在我使用 Proguard 的情况下?
- gradle 是否从我的库项目中提取了一些东西,这使得我的 apk 变大了?
- 如何确保仅将我的应用实际使用的库方法和类加载到 apk 中?
如果另一个文件与回答此问题相关,请告诉我。谢谢!
【问题讨论】:
-
您正在使用一些支持库。很正常,反正1M也不算大!
标签: android android-studio gradle proguard android-library