You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
override suspend fun buildInternal(identityConfiguration: IdentityConfiguration) {
val migrationManager = MigrationManager(this)
migrationManager.migrateOldStorage()
this.createIdentityContainer(identityConfiguration)
if (this.configuration.offline != AndroidNetworkConnectivityCheckerPlugin.Disabled) {
add(AndroidNetworkConnectivityCheckerPlugin())
}
androidContextPlugin = object : AndroidContextPlugin() {
override fun setDeviceId(deviceId: String) {
// call internal method to set deviceId immediately i.e. dont' wait for build() to complete
[email protected](deviceId)
}
}
add(androidContextPlugin)
add(GetAmpliExtrasPlugin())
add(AndroidLifecyclePlugin(activityLifecycleCallbacks)) <--- HERE
add(AnalyticsConnectorIdentityPlugin())
add(AnalyticsConnectorPlugin())
add(AmplitudeDestination())
(timeline as Timeline).start()
}
activityLifecycleCallbacks is defined as a val within .android.Amplitude, initialized during class creation. However, since all of this logic is happening in inits (one for the parent .core.Amplitude and one for the child .android.Amplitude), what's seemingly possible is a race to initialize, causing this crash:
Fatal Exception: java.lang.NullPointerException: Parameter specified as non-null is null: method com.amplitude.android.plugins.AndroidLifecyclePlugin.<init>, parameter activityLifecycleObserver
at com.amplitude.android.plugins.AndroidLifecyclePlugin.<init>(AndroidLifecyclePlugin.kt:3)
at com.amplitude.android.Amplitude.buildInternal$suspendImpl(Amplitude.kt:75)
at com.amplitude.android.Amplitude.buildInternal(Amplitude.kt:1)
at com.amplitude.core.Amplitude$build$built$1.invokeSuspend(Amplitude.kt:117)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
Possible Solution
Possible ideas, not sure of feasibility with other clients:
Don't construct things in init, let the caller decide when that logic happens
Pass ActivityLifecycleCallbacks to the constructor of .android.Amplitude so it's already initialized when needed
Steps to Reproduce
Open an app using the Amplitude Kotlin SDK
Initialize it immediately in Application.onCreate
Background the app
Rarely the app will crash
Environment
Unity Plugin Version: Amplitude-Android 1.19.4
Device: Motorola, Samsung, Oneplus, etc
Device OS and Version: Android 9 and above
The text was updated successfully, but these errors were encountered:
Expected Behavior
Calling the
Amplitude
constructor should not result in a crash.Current Behavior
The constructor of the
.core.Amplitude
class has logic for building the rest of the SDK - notably, buildInternal. The .android.Amplitude implementation overridesbuildInternal
and uses a class-level field:activityLifecycleCallbacks
is defined as aval
within.android.Amplitude
, initialized during class creation. However, since all of this logic is happening ininit
s (one for the parent.core.Amplitude
and one for the child.android.Amplitude
), what's seemingly possible is a race to initialize, causing this crash:Possible Solution
Possible ideas, not sure of feasibility with other clients:
init
, let the caller decide when that logic happensActivityLifecycleCallbacks
to the constructor of.android.Amplitude
so it's already initialized when neededSteps to Reproduce
Application.onCreate
Environment
The text was updated successfully, but these errors were encountered: