Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android APK file too big because of lib directory

Tags:

android

apk

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')
}
like image 828
cakan Avatar asked Apr 12 '16 08:04

cakan


People also ask

What is Lib folder in APK?

lib — directory with compiled native libraries used by your app. Contains multiple directories — one for each supported CPU architecture (ABI). META-INF — directory with APK metadata, such as its signature. AndroidManifest.

Where is the lib folder of Android project?

How to find the libs folder in Android Studio? If you are unable to find the libs folder in Android studio then open your android project in “Project” mode If the project is already opened in the “Android” mode. Then go to Your Project Name > app > libs and right-click on it and paste the downloaded JAR files.

What is the maximum size of APK file in Android?

Each expansion file can be up to 2GB in size. Users must run Play Store version 5.2 or higher to install 100MB APKs.


2 Answers

Problem was generated by PayPal SDK which includes card.io libraries. I have found that solution for my problem is to disable card.io card scanning:

packagingOptions {
    exclude 'lib/arm64-v8a/libcardioDecider.so'
    exclude 'lib/arm64-v8a/libcardioRecognizer.so'
    exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
    exclude 'lib/arm64-v8a/libopencv_core.so'
    exclude 'lib/arm64-v8a/libopencv_imgproc.so'
    exclude 'lib/armeabi/libcardioDecider.so'
    exclude 'lib/armeabi-v7a/libcardioDecider.so'
    exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
    exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
    exclude 'lib/armeabi-v7a/libopencv_core.so'
    exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
    exclude 'lib/mips/libcardioDecider.so'
    exclude 'lib/x86/libcardioDecider.so'
    exclude 'lib/x86/libcardioRecognizer.so'
    exclude 'lib/x86/libcardioRecognizer_tegra2.so'
    exclude 'lib/x86/libopencv_core.so'
    exclude 'lib/x86/libopencv_imgproc.so'
    exclude 'lib/x86_64/libcardioDecider.so'
    exclude 'lib/x86_64/libcardioRecognizer.so'
    exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
    exclude 'lib/x86_64/libopencv_core.so'
    exclude 'lib/x86_64/libopencv_imgproc.so'
}

Or to completely exclude card.io library:

dependencies {
    compile('com.paypal.sdk:paypal-android-sdk:2.14.1') {
        exclude group: 'io.card'
    }
}

I hope this will help somebody.

like image 136
cakan Avatar answered Oct 03 '22 15:10

cakan


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

like image 36
Hardik Amal Avatar answered Oct 03 '22 15:10

Hardik Amal