snowplow / snowplow-android-tracker

Snowplow event tracker for Android. Add analytics to your Android apps and games
http://snowplowanalytics.com
Apache License 2.0
109 stars 63 forks source link

Release build with R8 fails without #619

Open Anigif opened 1 year ago

Anigif commented 1 year ago

Describe the bug After bumping to 5.2 (5.1 works) we get this error while building in release mode with minify enabled:

WARNING: [app-module-path]/build/intermediates/merged_java_res/release/base.jar: R8: Unexpected reference to missing service class: META-INF/services/com.google.protobuf.GeneratedExtensionRegistryLoader.
ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in [app-module-path]/build/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class com.android.installreferrer.api.InstallReferrerClient$Builder (referenced from: void com.snowplowanalytics.core.tracker.InstallReferrerDetails$Companion.fetch(android.content.Context, kotlin.jvm.functions.Function1))
Missing class com.android.installreferrer.api.InstallReferrerClient (referenced from: com.android.installreferrer.api.InstallReferrerClient com.snowplowanalytics.core.tracker.InstallReferrerDetails$Companion$fetch$1.$referrerClient and 2 other contexts)
Missing class com.android.installreferrer.api.InstallReferrerStateListener (referenced from: void com.snowplowanalytics.core.tracker.InstallReferrerDetails$Companion.fetch(android.content.Context, kotlin.jvm.functions.Function1) and 1 other context)

The content of missing_rules.txt is:

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.android.installreferrer.api.InstallReferrerClient$Builder
-dontwarn com.android.installreferrer.api.InstallReferrerClient
-dontwarn com.android.installreferrer.api.InstallReferrerStateListener

To Reproduce Bump to 5.2 and don't add the installreferrer dependency.

Additional context We haven't understood it as required and we're not sure we want to log that particular entity.

matus-tomlein commented 1 year ago

Hi @Anigif, thanks for reporting the issue!

The installreferrer dependency is indeed an optional dependency – if it is not added to your project, the tracker will not call it's APIs and won't track the entity.

I can reproduce the message about missing classes when building an app withe minify, but it is only reported as a warning in my case. Do you have some setting enabled that turns warnings into errors?

Anigif commented 1 year ago

Yeah, think that's true. I'm not 100% sure what flag causes this, but we have various settings that sets warnings as errors. So in theory it should be safe to ignore these warnings as a workaround?

matus-tomlein commented 1 year ago

Yes, exactly, it is safe to ignore the warning because the tracker checks for the presence of classes in the package and if they are not present, it does not use them at all.

It would be ideal if we could find a way to avoid the warnings but, to be honest, I wasn't able to figure out how to do that. I haven't found a way to remove certain code (such as you would with a Macro in C-like languages) from the package if the required package is not present. If anyone has ideas how to achieve that, please let us know.