Remove unused fonts from build to reduce APK size
masterIf you do not need all the supported fonts (Roboto, Roboto Condensed, Roboto Slab, Roboto Mono), you can add a Gradle task to remove specific font files from the merged assets during the build process. For example, to remove RobotoSlab fonts:
android.applicationVariants.all{ variant ->
variant.mergeAssets.doLast {
File fonts = file("$variant.mergeAssets.outputDir/fonts")
if (fonts.exists()) {
for (File file : fonts.listFiles()) {
if (file.getName().contains("RobotoSlab")) {
println("delete " + file.getName() + " font")
file.delete()
}
}
}
}
}