0

What really kills me, I did changes and changes over again(from layouts ...) to fight against this, what's really strange my app does not do heavy stuff(minimum functionality).

I use 7 fragments, and FragmentContainerView , the default fragment contains just buttons to navigate to other fragments and adview

I cleared fragments from codes, guess what stills slow in app start, which leaves two possibilities, either gradle or corrupt assets(vector only)

my gradles:

buildscript {

    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
        classpath 'com.google.firebase:perf-plugin:1.4.1'
    }
}
plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.firebase.firebase-perf'



}

android {
    compileSdk 32
    buildToolsVersion '30.0.3'
    defaultConfig {
        applicationId "com.example.toannn"
        minSdk 21
        targetSdk 32
        versionCode 75
        versionName "8.4"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

    }
//    buildFeatures.viewBinding = true
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
        }
        release {
            minifyEnabled true
            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

}

dependencies {
    implementation "androidx.fragment:fragment-ktx:1.4.1"
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    //searchable spinner
    implementation project(path: ':searchableSpinner')
    //navigation
    implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
    //testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    //ads admob
    implementation 'com.google.android.gms:play-services-ads-lite:20.0.0'
    //firebase
    implementation platform('com.google.firebase:firebase-bom:27.0.0')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-perf-ktx'

    //rx kotlin and java android
    //implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
    //debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
    //dimension
    implementation 'com.intuit.sdp:sdp-android:1.0.6'
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    //splash screen
    //implementation 'androidx.core:core-splashscreen:1.0.0-rc01'
    // Preferences DataStore
    implementation "androidx.datastore:datastore-preferences:1.0.0-alpha04"

    // Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

    // Coroutine Lifecycle Scopes
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
    // For Kotlin
    implementation 'androidx.work:work-runtime-ktx:2.7.1'
    implementation 'com.google.firebase:firebase-core:18.0.0'
}
Yuba Sin
  • 1
  • 2
  • Have you tried [Strict Mode](https://developer.android.com/reference/android/os/StrictMode)? My guess is you're doing something programmatically that's causing this, like a database/network operation on the main thread. – Gavin Wright Jun 28 '22 at 21:38
  • as I said Icleared the codes and it stills, and by the way I use rxjava for database – Yuba Sin Jun 28 '22 at 21:42

1 Answers1

0

There's no single answer to this - it's taking a while because it's doing a bunch of stuff before it can show the first activity and fragment (which happens after all the onCreate stuff runs). Ten seconds implies you're doing stuff that blocks the main thread, like a non-async database load, network calls etc - I don't know if you are, but that's the kind of thing that can add serious delays (this is assuming other apps aren't slow to load on your device as well).

The only way to know is to do some investigation. You should read this section on diagnosing slow app startup times - there's a lot of good general advice and tips on avoiding issues, and it also recommends profiling your app with the CPU Profiler, which will let you see exactly which method calls are taking up the bulk of the time, and you can look into fixing those bottlenecks. If you can't see anything obvious that's causing it, it's your best bet for finding some answers

cactustictacs
  • 17,935
  • 2
  • 14
  • 25