Skip to content

Tips for reducing bundle size #32

@Janneman84

Description

@Janneman84

Remove unused fonts

This package adds three math fonts to your app. These are about 350kb each, however you probably only need one. I created a pull request that lets you remove the unused font files from your bundle to save space:
#31

Or switch to my fork:
implementation 'com.github.Janneman84:AndroidMath:v1.0.5'

Once you switched add this to app build.gradle:

android {
    ...

    androidResources {
        ignoreAssetsPattern =
            // remove unused math fonts from app bundle
            "latinmodern-math.otf:" + //default math font
            "xits-math.otf:" +
            "texgyretermes-math.otf:" +
            // remove font license files from app bundle
            "README-Latin-Modern-Math.txt:" +
            "README-TeX-Gyre-Termes-Math.txt:" +
            "GUST-FONT-LICENSE.txt:" +
            "OFL.txt:"
    }
}

Then comment out the .otf of the font file(s) you want to keep.

When initializing MTMathView make sure to set its font right away, or it may cause crashes:

val mathView = MTMathView(context)
mathView.font = MTFontManager.xitsFontWithSize(20f)

Remove redundant binaries from apk

If you're using aab instead of apk below does not apply.

By default binaries will be compiled for both ARM and x86. However x86 can also run ARM binaries, so they're not strictly needed (unless performance is a concern). I tested this on an x86 Chromebook and it works fine.

By adding this to app build.gradle only arm binaries will be created, saving a few MB of bundle size:

android {
    ...

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

Removing the v7a could even be considered, but apparently some obscure devices still use it.

You can use the apk analyzer to check if it all works.

Note that this affects the creation of all binaries, not just the one from AndroidMath. So be careful if you're using other packages that create binaries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions