Home > database >  'import androidx.compose.material3.*' vs 'import androidx.compose.material3."sev
'import androidx.compose.material3.*' vs 'import androidx.compose.material3."sev

Time:05-06

Understandably the asterisk symbol (import androidx.compose.material3.*) imports all resources, but is it more or less efficient and resource-hungry than only using the imports a project needs? e.g. using several imports instead of *.

Scenario 1

import androidx.compose.material3.*

Scenario 2

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MediumTopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text

CodePudding user response:

It is efficient. Android Studio will import named classes until they become too many, in which case it will default to importing all under the concerned package. The thing is, during build (final release i), checks are in place to ensure all unused resources are kept from being packaged in the build. Something like minifyEnabled in the build files also does something similar. Even if they do end up getting packaged, it is still fine. That is because they are just a bunch of text files that weigh KBs, which are further compressed during the build to less than you'd expect. So, there's no practical paranoia here that those would bloat your apk. Relax,

  • Related