【问题标题】:Why APK created by Android Studio is larger than APK created by Eclipse?为什么 Android Studio 创建的 APK 比 Eclipse 创建的 APK 大?
【发布时间】:2016-01-20 08:09:58
【问题描述】:

我的 Eclipse 创建的 APK 是 900K,但 Android Studio 是 1.62MB。代码是一样的。为什么?在 Eclipse 中,我将 facebook-sdk.jar、google-analytics.jar 和其他 jar 添加到我的库中。在Android Studio中,两个build.gradle如下:

  1. 项目中的build.gradle

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
            classpath 'com.google.gms:google-services:1.3.0-beta1'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
  2. 模块中的build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    
    android {
        compileSdkVersion 21
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            applicationId "com.xxx.xxx"
            minSdkVersion 15
            targetSdkVersion 21
        }
    
        buildTypes {
            release {
                shrinkResources true
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            }
        }
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile 'com.facebook.android:facebook-android-sdk:4.6.0'
        compile 'com.android.support:support-v4:21.0.3'
        //    compile 'com.google.android.gms:play-services:7.5.+'
        compile 'com.google.android.gms:play-services-analytics:7.5.0'
        compile files('libs/stickylistheaders_lib.jar')
    }
    

【问题讨论】:

  • 你在每一个中构建了哪个 apk?发布还是构建?
  • 发布。我生成签名的apk。如果我选择调试类型,apk的大小大于2MB。
  • 您可以随时使用 winrar 或类似程序打开 apk 以检查 apk 的哪个部分占用了这么多空间
  • 好的,我试试。谢谢!

标签: android eclipse android-studio apk


【解决方案1】:

build.gradle 中使用它,问题出在 gradle build 中

 buildTypes {

    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

    }

}

【讨论】:

  • 但我的 buildType 是 release。我生成签名的 apk。
  • 在生成签名apk之前配置proguardFiles。
  • 我的 Eclipse 项目中的 proguard-project.txt 与我的 Android Studio 项目中的文件相同。而如果我生成调试 apk,则 APK 大小大于 2MB。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 2015-02-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多