Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

barteksc/AndroidPdfViewer massive APK Size

Tags:

We included this AndroidPdfViewer library to support viewing of PDF reports in the app. It lead to massive increase in APK size from 4.7Mb to 20.1Mb .

Is there a way to reduce this size. Let me know where and what to tinker around to help or solve this.

I am familiar with proguard and have it configure for my app with reasonable success.

like image 540
appbootup Avatar asked Feb 20 '17 05:02

appbootup


2 Answers

Why resulting apk is so big?

As stated in the documentation by barteksc/AndroidPdfViewer

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.

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

like image 106
Peter R Avatar answered Sep 25 '22 10:09

Peter R


You have to generate Multiple APKs for different devices, by doing this you can reduce the size of apk up to 10 MB less than previous. Add below code to build.gradle (Module:App)

 android{
   .....
    splits {
        abi {
            enable true
            reset()
            include 'x86_64', 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips'
            universalApk false
        }




         }
        .....


      }
ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, mips: 4, 'x86': 5, 'x86_64': 6]
import com.android.build.OutputFile

// For each APK output variant, override versionCode with a combination of
// ABI APK value * 1000 + defaultConfig.versionCode
android.applicationVariants.all { variant ->
    // assign different version code for each output
    variant.outputs.each { output ->
        output.versionCodeOverride =
                project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000 + android.defaultConfig.versionCode
    }
}

Whatch video here https://youtu.be/bP05Vpp49hs for detail explanation on how to do it.

like image 40
user3344008 Avatar answered Sep 22 '22 10:09

user3344008