Android Studio新项目文件大小太大
我刚刚在android Studio 2.2.3中创建了一个新的android项目,只有一个空的活动,但它仍然在设备上使用了4.11 MB,我认为这是一个很大的问题,因为它确实包含一个空的活动。为什么要占用这么多空间?有可能缩小它的尺寸吗?我下载的应用程序功能更多,图片、颜色等更多,小于2MB 下面是我用来创建项目的步骤 然后,在Sony Xperia上运行应用程序后,我得到了这些信息 在分析我得到的内存时 已分配3MB和ust 1MB空闲 这是build.gradle文件:Android Studio新项目文件大小太大,android,android-studio,Android,Android Studio,我刚刚在android Studio 2.2.3中创建了一个新的android项目,只有一个空的活动,但它仍然在设备上使用了4.11 MB,我认为这是一个很大的问题,因为它确实包含一个空的活动。为什么要占用这么多空间?有可能缩小它的尺寸吗?我下载的应用程序功能更多,图片、颜色等更多,小于2MB 下面是我用来创建项目的步骤 然后,在Sony Xperia上运行应用程序后,我得到了这些信息 在分析我得到的内存时 已分配3MB和ust 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'
}
在您的构建中启用缩小和缩小资源。渐变:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
它将从apk中删除未使用的代码和资源调试apk或发布apk?如果调试apk,它总是比发行版稍大一些。在发布模式下,执行
minifyEnabled=true
,shrinkResources=true
,zipalingenabled=true
。它会将您的发布文件大小缩小到调试文件的30%左右(基于我的经验)。“为什么它占用了这么多空间?”--很可能您最终得到的是appcompat-v7
,这将增加约1MB的APK大小。我建议你编辑你的问题并发布你的app/build.gradle
文件,这样我们就可以看到你有什么依赖关系。@Commonware我已经更新了这个问题以包含build.gradle文件。appcompat-v7
将给你的APK增加1MB,而design
应该增加300KB。您可以在AndroidStudio 2.2+中使用Build>Analyze APK来查看实际APK有多大以及空间在哪里。您不必使用appcompat-v7
或design
(尽管design
需要appcompat-v7
);在设置初始活动时,您可以通过自己的选择获得这些信息。在Android Studio 2.2.3中,设置新项目、选择空活动模板并取消选中“向后兼容性”复选框将跳过appcompat-v7
(在任何情况下,空活动都不应拉入design
)。