In my project, I have used libraries which require multidex support. Based on the research I did, I came to know that it causes delay during app start up.
I have enabled multidex feature in gradle. defaultConfig { multiDexEnabled true }
I used to get NoClassDefFound Exception for kitkat devices so I added the following:
I have added application name in manifest as android:name="android.support.multidex.MultiDexApplication"
and extended my application class with MultiDexApplication.
I know any one of the above is sufficient but I have just written both.
I tried different ways to optimize the duration of start up like the following :
1.added productFlavors { dev { minSdkVersion 21 } prod { minSdkVersion 14 } }
dexOptions { preDexLibraries false javaMaxHeapSize "4g" }
I imported only required google play service's libraries instead of importing full library.
Can you please suggest me an approach to improvise the duration because its actually taking more than 10 seconds and some times even more than that in some of the devices?
Or Is there any other reason that might be causing the delay apart from multidex?
Thanks in advance.
I have added my build.gradle file contents :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.app"
minSdkVersion 17
targetSdkVersion 23
versionCode 3
versionName "1.2"
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "10g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/ormlite-android-4.28.jar')
compile files('libs/ormlite-core-4.28.jar')
compile project(':volley')
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile 'com.android.support:design:23.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.1.2'
compile 'org.jsoup:jsoup:1.8.2'
compile 'org.twitter4j:twitter4j:4.0.3'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.1.0'
compile 'com.orhanobut:dialogplus:1.11@aar'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'co m.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'org.java-websocket:Java-WebSocket:1.3.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
Android uses the Time to initial display and Time to full display metrics to optimize cold and warm application startups. Android Runtime (ART) uses the data from these metrics to efficiently precompile code for optimization of future startups.
Use lazy initialization: parts of your application don't need to be initialized during startup. Try to identify those parts and delay the initialization as much as possible — e.g., the user profile might only be necessary on the profile activity and not very useful during startup.
On the App start-up time page inside Android Vitals (on Google Play console), you can see details about when your app starts slowly from cold, warm, and hot system states. These metrics are automatically calculated, without any development effort.
There is a strange issue with newly released Android Studio 2.0 or 2.1. First time of launching application take longer than usual. This issue happens only in debug mode and not effect to your released APK. Also I was suffering this issue and found this solution.
Settings/Preferences(Mac) → Build, Execution, Deployment → Instant Run and uncheck Instant Run
This will solve your problem and if it is please mark as accepted answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With