Search code examples
androidandroid-support-library

How can I reduce the size of a library folder?


my application is to just open pdf book when I use buttons and the size of pdf files is small then 1MB ! this is my dependencies :

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'org.apache.commons:commons-io:1.3.2'
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

the size of the lib folder is 17MB

see the image please


Solution

  • https://github.com/barteksc/AndroidPdfViewer

    Why resulting apk is so big? Android PdfViewer depends on PdfiumAndroid, which is set of native libraries (almost 16 MB) for many architectures. Apk must contain all this libraries to run on every device available on market. Fortunately, Google Play allows us to upload multiple apks, e.g. one per every architecture. There is good article on automatically splitting your application into multiple apks, available here. Most important section is Improving multiple APKs creation and versionCode handling with APK Splits, but whole article is worth reading. You only need to do this in your application, no need for forking PdfiumAndroid or so.

    The solution is to split your APK. Read more here: https://developer.android.com/studio/build/configure-apk-splits.html#configure-abi-split