What is libclasifier_jni.so in android's apk?

Viewed 633

My android apk is around 22MB, even when i have not used anything heavy. After analyzing the apk file i found a directory "lib" which contains a file name "libclasifier_jni.so" for different architectures, I am not sure where it is coming from. below is screenshot for sameenter image description here

Could you please tell me what i'm missing here?

Below is build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.pixyfisocial"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 24
        versionName '5.0.0'
        multiDexEnabled true
        testApplicationId "com.pixyfisocial.screens.presenters"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
    productFlavors {
    }
}

configurations {
    all {
        exclude module: 'json'
        exclude module: 'commons-logging'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    testCompile 'org.powermock:powermock-api-mockito2:1.7.4'
    // https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4
    testCompile 'org.powermock:powermock-module-junit4:1.7.4'
    // https://mvnrepository.com/artifact/org.mockito/mockito-core
    testCompile 'org.mockito:mockito-core:2.8.9'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.support:appcompat-v7:27.1.1'
    compile 'com.android.support:recyclerview-v7:27.1.1'
    compile 'com.android.support:cardview-v7:27.1.1'
    compile 'com.android.support:design:27.1.1'
    implementation 'com.facebook.android:facebook-android-sdk:4.33.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.clans:fab:1.6.2'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'
    compile 'com.facebook.android:account-kit-sdk:4.+'
    compile 'com.android.support:support-v4:27.1.1'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.google.firebase:firebase-appindexing:15.0.1'
    compile 'com.google.firebase:firebase-auth:16.0.1'
    compile 'com.google.android.gms:play-services-auth:15.0.1'
    compile 'com.google.firebase:firebase-invites:16.0.0'
    compile 'com.android.support:customtabs:27.1.1'
    compile 'com.google.firebase:firebase-ml-vision:16.0.0'
    compile 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0'
    compile 'com.github.greenfrvr:hashtag-view:1.3.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'
    implementation project(':pixyfi-data')
    implementation project(':pixyfi-services')
    implementation project(':utility')
}
apply plugin: 'com.google.gms.google-services'
3 Answers

What is libclasifier_jni.so in android's apk?

You have used Firebase Vision Image library, that contains these SO files.

compile 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0'

My android apk is around 22MB

You must not exclude those ndk files from apk via any gradle configuration, if you are using Fragment Vision library in your app.

What is solution?

1. Build multiple APKs

Although you should build a single APK to support all your target devices whenever possible, that might result in a very large APK due to files needed to support multiple screen densities or Application Binary Interfaces (ABIs). One way to reduce the size of your APK is to create multiple APKs that contain files for specific screen densities or ABIs.

Play store supports splitting apk, in which you can make multiple apk for multiple cpu ABI. There are 4 SO files in your app. Each is 3-4MB of size. So if you use split APK then unnecessary 12MB will be reduced in every APK.

2. Include only armeabi-v7a and arm64-v8a

Let me tell you useful information about ABI percentage statics. If you don't really care about all ABIs, then you can include two ABI ndks. Earlier days I posted an detailed statics Answer Here, which will help you more understanding ABI percentage.

  • armeabi-v7a (required — most popular architecture nowadays)
  • arm64-v8a (required — newer version of armeabi-v7a)
  • x86 (optional, very limited number of devices, like Asus Zenfone 2, Genymotion/ Android emulator)
  • x86_64 (optional, very limited number of devices, like Asus Zenfone 2, Genymotion/ Android emulator)

So if you include armeabi-v7a and arm64-v8a architectures then you cover up 99% of Android devices.

This is how you can include only these two ABIs in your APK.

buildTypes {
    release {
        ndk {
            abiFilters "arm64-v8a", "armeabi-v7a"
        }
    }

image

This blog will help you in configuring gradle for multiple APK and ABI filter and understand ABI management better. Also I must say Google's Android page has perfect information that you need.

It is native library compiled and attached with your apk. check your cmake script or ndk Android.mk files. if you are not sure that where it is coming from then you can also exclude it from your apk for different architectures . In your gradle inside write these lines

android{
 packagingOptions {

        exclude 'lib/arm64-v8a/libclasifier_jni.so'
        exclude 'lib/armeabi/libclasifier_jni.so'
        exclude 'lib/armeabi-v7a/libclasifier_jni.so'
        exclude 'lib/mips/libclasifier_jni.so'
        exclude 'lib/mips64/libclasifier_jni.so'
        exclude 'lib/x86/libclasifier_jni.so'
        exclude 'lib/x86_64/libclasifier_jni.so'

    }
}

This specific lib is coming from this dependency:

    compile 'com.google.firebase:firebase-ml-vision-image-label-model:15.0.0'

You can go to the artifact link , download the aar and unzip it. You will see contents like the picture below:

enter image description here

Related