Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using global context when creating a tracker causes crashes on API 23 #601

Closed
frodstan opened this issue May 12, 2023 · 3 comments
Closed
Labels
type:defect Bugs or weaknesses. The issue has to contain steps to reproduce.

Comments

@frodstan
Copy link

Describe the bug
Initializing the sdk with a global context on Android 6 throws an exception. I have tried both with a static context and with context generator.

FATAL EXCEPTION: main Process: com.example.snowplow_test, PID: 17105 java.lang.NoClassDefFoundError: com.snowplowanalytics.core.globalcontexts.GlobalContextPluginConfiguration$$ExternalSyntheticLambda0 at com.snowplowanalytics.core.globalcontexts.GlobalContextPluginConfiguration.getEntitiesConfiguration(GlobalContextPluginConfiguration.kt:28) at com.snowplowanalytics.snowplow.configuration.PluginConfigurationKt.toStateMachine(PluginConfiguration.kt:62) at com.snowplowanalytics.core.tracker.ServiceProvider$makeTracker$builder$1.invoke(ServiceProvider.kt:293) at com.snowplowanalytics.core.tracker.ServiceProvider$makeTracker$builder$1.invoke(ServiceProvider.kt:262) at com.snowplowanalytics.core.tracker.Tracker.<init>(Tracker.kt:356) at com.snowplowanalytics.core.tracker.ServiceProvider.makeTracker(ServiceProvider.kt:297) at com.snowplowanalytics.core.tracker.ServiceProvider.getOrMakeTracker(ServiceProvider.kt:187) at com.snowplowanalytics.core.tracker.ServiceProvider.<init>(ServiceProvider.kt:87) at com.snowplowanalytics.snowplow.Snowplow.createTracker(Snowplow.kt:237) at com.example.snowplow_test.MainActivity.initializeSnowplow(MainActivity.kt:68) at com.example.snowplow_test.MainActivity.onCreate(MainActivity.kt:37)

To Reproduce
To reproduce this issue, create a new Android app from template with minimum Android SDK 23.

Add snowplow library (version 5.0.0 - 5.1.0, 4.x.x has worked for us previously).

Initialize the sdk in MainActivity onCreate() with a global context sent to Snowplow.createTracker()
Pasting in from documentation here will cause the crash:
https://docs.snowplow.io/docs/collecting-data/collecting-from-own-applications/mobile-trackers/custom-tracking-using-schemas/global-context/#static-entities

Run the app on a device or emulator with Android 6

Expected behavior
Snowplow will have initialized and is ready to send events

Device information (please complete the following information):

  • Device: Any device or emulator with Android 6 Marshmallow
  • OS: Android 6
  • Browser
  • Version
@frodstan frodstan added the type:defect Bugs or weaknesses. The issue has to contain steps to reproduce. label May 12, 2023
@matus-tomlein
Copy link
Contributor

matus-tomlein commented May 16, 2023

Hi @frodstan,

I think this is caused by the fact that the global context implementation uses Java 8 features underneath.

In order to make this work on older Android SDKs, you will need to add Java 8 desugaring support to your app. You can follow the instructions here. Basically you need to use Android Gradle Plugin v4 and add this to your build.gradle:

android {
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}

You can see the build.gradle for our demo app which has min SDK version set to 21 and works with global context as an example.

Hope this helps! Let us know if you run into any problems.

@frodstan
Copy link
Author

Awesome, this fixed the issue.
Thank you!

@robertossan
Copy link

Hi @matus-tomlein ,

I know that this problem is already "solved" using the proposed workaround, but Is there any other way to do it that does not involve having to add another dependency other than snowplow?

I´d prefer not having to include this third dependency

dpgmedia-gbero added a commit to dpgmedia-gbero/snowplow-android-tracker that referenced this issue Feb 13, 2024
…on of FocalMeterConfiguration would crash.

A thread (snowplow#601) in the issue tracker suggested to use of coreLibraryDesugaring but this might be avoided.

remove usage of java.util.function.* in order to get rid of library desugaring.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:defect Bugs or weaknesses. The issue has to contain steps to reproduce.
Projects
None yet
Development

No branches or pull requests

3 participants