我刚刚在 Android Studio 2.2.3 中创建了一个新的 Android 项目,其中只有一个空 Activity,但它仍然在设备上使用了 4.11 MB,我认为这个空间很大,因为它确实包含一个空 Activity。为什么它占用这么大的空间?是否可以减小其尺寸?我下载了功能更多、图片、颜色等更多的应用程序,并且小于 2MB。
以下是我用于创建项目的步骤。
然后,在 Sony Xperia 上运行该应用程序后,我得到了此信息。
在分析我得到的内存时。
已分配 3MB 和 1MB 空闲空间。
这是 build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.survey.research.surveycollect"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
testCompile 'junit:junit:4.12'
}
最佳答案
在 build.gradle 中启用缩小和资源收缩:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
它将从您的 apk 中删除未使用的代码和资源
关于Android Studio 新项目文件大小太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42180070/