Android Studio生成的Apk文件太大

时间:2015-10-17 03:36:06

标签: android eclipse android-studio material-design android-appcompat

A.S.生成的最简单的Hello World应用程序。差不多5MB!但在Eclipse中它只有大约100KB 当我创建一个项目时,A.S。默认情况下使用android.support:appcompat-v7。这是build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "test.elva.testapp"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.0'
}

在Eclipse中,如果将minSdkVersion设置为14,则项目不使用appcompat-v7库,并且该类在A.S中扩展为Activity,而不是AppCompatActivity

Apk detail pic.

1 个答案:

答案 0 :(得分:3)

由于您要包含不同的库,因此无法比较维度 在Android Studio中,您包含appcompat库,其中包含代码和资源,还有其他依赖项,如support-v4库。

您可以自定义build.gradle脚本。

例如,您可以删除AppCompat库,评论从dependencies块中删除该行

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //compile 'com.android.support:appcompat-v7:23.1.0'
}

AS使用AppCompatActivity作为标准。 是的,它是真实的。造成这种情况的原因很多,主要是在api 21下的材料设计的后退 如果没有appcompat,您就无法使用工具栏等视图或设计支持库提供的视图。

您可以在此处找到官方信息:

您还可以使用以下方法删除未使用的资源:

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

更多info here