简体   繁体   中英

Apk file generated from Android Studio too large

A simplest Hello World app generated from AS is almost 5MB! But in Eclipse it is only about 100KB and when I create a project, The AS use the android.support:appcompat-v7 by default. Here is 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'
}

In Eclipse, if you set minSdkVersion up to 14, the project doesn't use appcompat-v7 library,and the class is extended to Activity ,not AppCompatActivity in AS

Apk detail pic.

You can't compare the dimension since you are including different libraries.
In Android Studio you are including the appcompat library with has code and resources, and has other dependencies like support-v4 library.

You can customize your build.gradle script.

For example you can remove the AppCompat library, commenting on removing the line from the dependencies block

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

AS is using the AppCompatActivity as standard. Yes it is true. There are many reasons for that, mainly the backport of material design under api 21.
Without the appcompat, you can't use view like as the Toolbar or views provided by the Design support library .

You can find official info here:

You can also remove the unused resources using:

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

More info here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM