android - Android Studio 生成的 Apk 文件太大

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

从 A.S. 生成的最简单的 Hello World 应用程序差不多5MB了!但在 Eclipse 中只有 100KB 左右 当我创建一个项目时,The 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 库,并且该类扩展为 Activity,而不是 AppCompatActivity

Apk detail pic.

最佳答案

您无法比较维度,因为您包含不同的库。
在 Android Studio 中,您将包含 appcompat 库,其中包含代码和资源,以及其他依赖项,例如 support-v4 库。

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

例如,您可以删除 AppCompat 库,并从 dependency block 中删除该行进行注释

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

AS 使用 AppCompatActivity 作为标准。 是的,它是真实的。原因有很多,主要是 API 21 下 Material Design 的反向移植。
如果没有 appcompat,您就无法使用工具栏之类的 View 或设计支持库提供的 View 。

您可以在这里找到官方信息:

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

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

更多 info here .

关于android - Android Studio 生成的 Apk 文件太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33182459/

相关文章:

android - Ant 构建脚本 : cannot find android. jar

java - Eclipse 和 cronTriggered 作业调试

java.lang.NoClassDefFoundError : org/apache/hadoop/conf/Configuration 错误

android - 带有 spongycaSTLe LICENSE.class 的 java.util.zip.ZipException

java - setImage经常不阻塞UI线程Android

java - android-RuntimePermissions 示例代码不起作用

android - Settings.Secure.Android_ID 可以为空吗?

java - 如何在从 Unity 调用的 Java 插件中创建 Android 处理程序

java - 在 TOMCAT 7 servlet 中为发布请求启用 CORS

android-studio - Flutter Doctor (Incorrectly?) 报告 Android Studio Flutter Plugin Not Installed