Anyone noticed that APK size has increased drastic...
# compose
d
Anyone noticed that APK size has increased drastically when using compose. Starter application in XML takes
4.2 MB
whereas starter app in Compose is
7.2 MB
having 5
.dex
files. Why there are so many dex files in a starter app? Edit: I noticed that starter app in XML also has 3 dex files, why is this happening, does this have anything to do with recent versions of Android gradle plugin?
a
It's meaningless to measure APK size using debug builds. You should use R8-enabled release builds.
a
Also, if it's a pure compose app, you can remove the dependencies on AppCompat and Material (as Tivi did), which also saves a lot.
👍 1
t
That article misses an intermediary step as the size reduction only occurs after removal of appcompat and material. From real world test with R8 compose add about 1Mb of DEX. Default created application from AS still by default use the material lib theme + app compat hence size increase. I'm not sure an empty default app should still do that.
d
Alright I compared with release unsigned APK with proguard enabled by removing
androidx.core:core-ktx
,
androidx.appcompat:appcompat
,
androidx.compose.ui:ui-tooling-preview
and
androidx.lifecycle:lifecycle-runtime-ktx
from Compose app and the APK got reduced to
1.9MB
as compared to XML app's
1.5MB
But the article says APK size got less as compared to older XML approach. how exactly? Could it be
Fragments
?
I also tried to remove
com.google.android.material:material
but then I started getting errors as they are used to define themes which are used in AndroidManifest's
android:theme
t
It is material, you need to remove it from the themes too https://github.com/chrisbanes/tivi/blob/main/app/src/main/res/values/themes.xml
👍 1
d
Removing material library reduced the APK size to
504 KB
I have to say I'm impressed
🤯 1
434 Views