androidkotlinandroid-jetpack-composedagger-hiltgradle-kotlin-dsl

Why apps made in Jetpack compose are larger. Any Solution?


Why apps made in compose are too much larger in size, the same app that had been made using xml is around 5-6mb but in compose it's going around 20mb why is there any option that I need to enable or anything else.

Also this might be a bug or something but If I create an application using jetpack and install it in my real android device (iqoo 7 12gbram) the initial size of app will be tripled after I'm opening the app. here is the built apk size (10mb which is too much because its an empty application )

Build Apk Size Build Apk Size Image

here is after the installation on real device

Size On Real Device Size On Real Device Image

here is the size of app in emulator

Size on Emulator Image

Some applications in xml had 15-20 MB but same in compose is going over 100 MB after installation.

I had created an empty application without any content in it and just added some dependencies like hilt, and splash screen here is the build.gradle.kts file

is anything I'm missing?

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("dagger.hilt.android.plugin")

    kotlin("kapt")
}

android {
    namespace = "com.bharath.project_learnandroiddevelopment"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.bharath.project_learnandroiddevelopment"
        minSdk = 26
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation("androidx.core:core-ktx:1.9.0")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
    implementation("androidx.activity:activity-compose:1.8.0")
    implementation(platform("androidx.compose:compose-bom:2023.03.00"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.10.0")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")


    // Imported Dependencies

    /*
    Dagger Hilt : 💉 Dependency Injection
//     */
    implementation("com.google.dagger:hilt-android:2.48")
    kapt("com.google.dagger:dagger-compiler:2.48") // Dagger compiler
    kapt("com.google.dagger:hilt-compiler:2.48")   // Hilt compiler
    implementation("androidx.hilt:hilt-navigation-compose:1.1.0-beta01")

    /*
    Compose Navigation 🧭
     */
    implementation("androidx.navigation:navigation-compose:2.7.4")

    /*
    Splash Screen 💦
     */
    implementation("androidx.core:core-splashscreen:1.0.1")


    /*

     */
}

I had tried to use minify, shrink resources but that's not working.


Solution

  • I am going to assume that you are talking about your app in debug mode which is normal for compose to be large in size and slow in terms of speed but when your app is finished all you have to do is create it in release mode and i highly advice you to use R8/ProGuard it will reduce the size of the app significantly.