简体   繁体   English

尝试在 Android 应用程序中加快启动速度

[英]Trying to speed up the startup launch in an Android app

in the process of improving my Android app startup launch time, I ended up with the concept of multidex and the fact that the number of components added in build.gradle slows down the launch time.在改进我的 Android 应用程序启动启动时间的过程中,我最终想到了 multidex 的概念以及 build.gradle 中添加的组件数量减慢启动时间的事实。

So how can I improve that, how can I lazy init some of the components that are not required at startup?那么我该如何改进呢,我怎样才能懒惰地初始化一些在启动时不需要的组件呢? And using the lazy initialization, how can I identify the 3rd party components by class name.并且使用延迟初始化,如何通过 class 名称识别第 3 方组件。 I understand that I could generate a maindexlist file, listing all the class names.我知道我可以生成一个 maindexlist 文件,列出所有 class 名称。 But I'm not sure I know how to continue from that.但我不确定我知道如何继续。 Do I have to lazy init all the components one by one (I mean those unnecessary at startup)?我是否必须一个一个地懒惰地初始化所有组件(我的意思是那些在启动时不需要的组件)? Is this a good approach to speed my app launch time?这是加快我的应用程序启动时间的好方法吗? Besides that, is the profiling in Android Studio shwoing also the startup initialization of those 3rd party components?除此之外,Android Studio 中的分析是否也显示了那些第 3 方组件的启动初始化? If yes, how can I see them in the profile trace?如果是,我如何在配置文件跟踪中看到它们?

Perhaps I'm not being very clear.也许我不是很清楚。 My app build.gradle file looks like this:我的应用程序 build.gradle 文件如下所示:

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.preference:preference:1.1.0'
implementation "androidx.startup:startup-runtime:1.0.0"

//GOOGLE PLAY SERVICES
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-ads:19.7.0'

// Google Sign In SDK (only required for Google Sign In)
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.android.gms:play-services-auth-api-phone:17.5.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'

//places
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.libraries.places:places:1.1.0'


def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"

//maps
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'

implementation project(path: ':app:libs:linkedin-sdk')
implementation project(path: ':app:libs:ntp:library')
implementation project(path: ':app:libs:ntp:library-extension-rx')
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"


testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.leanback:leanback-preference:1.0.0'

implementation "android.arch.lifecycle:extensions:1.1.1"

implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-database:19.5.0'
//implementation 'com.firebaseui:firebase-ui-database:1.0.1'

implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-functions:19.0.2'

// Facebook Android SDK (only required for Facebook Login)
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

//twitter
implementation 'com.twitter.sdk.android:twitter:3.1.1'

implementation 'com.squareup.picasso:picasso:2.5.2'


//billing
implementation 'com.android.billingclient:billing:3.0.0'

//geo fire
implementation 'com.firebase:geofire-android:3.0.0'

//gson
implementation 'com.google.code.gson:gson:2.8.6'


// Room Architecture Components.
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'

//biometrics
implementation 'androidx.biometric:biometric:1.0.1'

implementation 'com.fasterxml.jackson.core:jackson-core:2.10.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.1'

implementation 'org.whispersystems:signal-service-android:2.13.9'

Thanks for your answers!感谢您的回答!

These "components" are loaded at start because the OperationSystem cannot know when a component will be required, so... If you know that (ie) Picasso is not loaded until "Page 9", then the only solution is to manually build a separated APK and MANUALLY load its class/dex file in runtime when needed.这些“组件”是在开始时加载的,因为 OperationSystem 无法知道何时需要某个组件,所以...如果您知道(即)毕加索直到“第 9 页”才加载,那么唯一的解决方案是手动构建一个分离的 APK 并在需要时在运行时手动加载其类/dex 文件。 The procedure is not very easy and needs programming knownledge about Dex loading.该过程不是很容易,需要有关Dex加载的编程知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM