appbootup
appbootup

Reputation: 9537

barteksc/AndroidPdfViewer massive APK Size

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.

Upvotes: 5

Views: 3965

Answers (4)

Peter R
Peter R

Reputation: 419

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

Upvotes: 2

Mrudul Tora
Mrudul Tora

Reputation: 768

I also faced the same problem, but this is very easy as of now to reduce the apk sizes by using android app bundles. Firstly in build.gradle(Module: app) add these lines inside android { } brackets.

bundle {
    abi {
        enableSplit = true
    }
}

This will handle apk splits on the basis of architecture. Now, also remember to add this line in proguard-rules.pro

-keep class com.shockwave.**

If you will not add this line in proguard-rules.pro then your app will crash in release version. Now, after this go to Build and then select, Generate Signed Bundle/apk. From here, generate a signed bundle. Bundles are generated in very same way, as the apk's are generated. Then, upload your bundle(.aab file) on Google Play Console and you will see that every device gets different apks depending upon their architecture. This is the most easiest way to reduce the app size.Multiple apk concept is more complicated.

So,I suggest you to use this way.

Upvotes: 0

Sarath SVS
Sarath SVS

Reputation: 49

If anyone is looking for a lightweight pdf viewer for your app, then try this one

Use this library

It helped me to reduce the app size from 27MB to 10MB because of the barteksc-androidpdfviewer requires more space

Upvotes: 0

user3344008
user3344008

Reputation: 21

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.

Upvotes: 2

Related Questions