androidapk

Android APK file too big because of lib directory


I'm building an Android application which size was around 4MB APK file. From a couple of weeks ago, when building signed app, generated APK file is around 17MB.

After investigating why is this happening, I've discovered that new APK archives contain /lib directory which didn't exist on old APKs that were 4MB in size. Does anyone know why this lib directory suddenly appears in APK archive and is there a way to remove it?

Structure of /lib directory inside APK archive is:

/lib
    /arm64-v8a
    /armeabi
    /armeabi-v7a
    /mips
    /x86
    /x86_64

I have recently updated Android Studio to 2.0 and also upgraded gradle. Can this be an issue and is there some configuration parameters that can solve this problem?

My gradle file looks like this:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
        classpath 'io.fabric.tools:gradle:1.+'

    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    flatDir { dirs 'aars' }
}

android {
    // when changing this, YOU MUST change C:\AndroidADT\sdk\build-tools\xx.yy.zz\dx.bat to have -> set java_exe=C:\Windows\System32\java.exe
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 21
    }
    def homeDir = System.getenv('HOMEDRIVE') + System.getenv('HOMEPATH');

    signingConfigs {
        cinema {
            storeFile = file("keystore\\cinema.keystore.jks")
            storePassword = "cinema"
            keyAlias = "cinema"
            keyPassword = "cinema"
        }
        dev {
            storeFile = file("keystore\\development.keystore.jks")
            storePassword = "development"
            keyAlias = "development"
            keyPassword = "development"
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        cinema {
            debuggable false
            signingConfig signingConfigs.cinema
            jniDebuggable false
            applicationIdSuffix ".cinema"
        }
        dev {
            debuggable true
            signingConfig signingConfigs.dev
            jniDebuggable true
            applicationIdSuffix ".dev"
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src', 'src-gen']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']

            assets.srcDirs = ['assets']
        }
        debug {
        }
        dev {
            res.srcDirs = ['res_dev']
        }
        cinema {
            res.srcDirs = ['res_cinema']
        }
        androidTest.setRoot('tests')
    }


    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE.txt'
    }
}

dependencies {
    compile 'joda-time:joda-time:2.3'
    compile 'com.android.support:support-v4:21.0.0'
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.google.android.gms:play-services-plus:8.3.0'
    compile 'com.google.android.gms:play-services-auth:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.facebook.android:facebook-android-sdk:4.5.0'
    compile 'com.markupartist.android.widget:pulltorefresh:1.0@aar'
    compile 'com.paypal.sdk:paypal-android-sdk:2.13.3'
    compile('com.crashlytics.sdk.android:crashlytics:2.2.0@aar') {
        transitive = true;
    }
    compile files('libs/gson-2.2.4.jar')
    compile files('libs/twitter4j-core-4.0.2.jar')
    compile files('libs/core-3.1.0.jar')
    compile files('libs/estimote-sdk-preview.jar')

    compile files('libs/commons-codec-1.10.jar')
    compile files('libs/commons-lang-2.6.jar')
    compile files('libs/FastPaySDK_pro.jar')
}

Solution

  • Try this to exclude SO file from the release build

    android {
    buildTypes {
        release {
            ndk {
                abiFilters "armeabi-v7a", "armeabi" // includes ARM SO files only, so no x86 SO file
            }
        }
      }
    }
    

    Have not tested,maybe you can try out: abiFilters "" to exclude all the .SO files