I have a multi-module app and recently, I moved the instrumented tests to a single and separate module.
My setup seems fine since I can build, run unit tests and also instrumented tests.
I just noticed that the instrumentation APK is huge (~170MB) while the app APK itself is smaller (~20Mb).
Inspecting the APK, I noticed there are a lot of fonts (.ttf) being added to the test app.
Below is my setup:
plugins {
alias (libs.plugins.android.test) // "com.android.test"
alias (libs.plugins.kotlin.android)
alias (libs.plugins.ksp)
alias (libs.plugins.hilt.dagger)
}
android {
targetProjectPath = ":example:app:application"
namespace = "com.example.androidtest"
defaultConfig.apply {
testInstrumentationRunner = "com.example.tests.TestRunner"
}
....
}
After running:
./gradlew :example:app:application:assembleFullDebug :example:androidtest:assembleFullDebug
or
./gradlew :example:androidtest:connectedFullDebugAndroidTest
I get two APKs:
// Instrumentation app.. This is the problematic one
./example/app/androidtest/build/outputs/apk/full/debug/androidtest-full-debug.apk
// Actual app. Its size is normal.
./example/app/application/build/outputs/apk/full/debug/full_debug_v2.0.0.apk
Does anyone know from where those fonts are coming? If I analyze the actual app APK, those fonts do not exist. They are being added only to this instrumentation auxiliary APK.
One possible solution I found was to remove /fonts
folder from the APK using packing
options:
packaging {
resources.excludes += "/fonts/*"
}
With this change alone, the APK size was reduced to ~40Mb