Skip to content

Attempting to use both the Java and Android tracker in the same project causes DuplicateClass errors #383

@mezpahlan

Description

@mezpahlan

Describe the bug
I have a library A that uses the java-tracker as a dependency. It's a pure Java project because it needs to be shared with other pure Java projects. That is to say it uses the Gradle java plugin.

I also have an application B that uses the android-tracker as a dependency. This uses the Gradle android-application plugin but otherwise contains a mix of Android libraries and Java libraries.

Both scenarios are valid until you try and use library A in application B as dependency. Gradle then complains that there is a DuplicateClass error.

Duplicate class com.snowplowanalytics. snowplow. tracker. DevicePlatform 
found in modules 
snowplow-android-tracker- 6. 0. 3. aar -> snowplow-android-tracker- 6. 0. 3- runtime (com.snowplowanalytics: snowplow-android- tracker: 6. 0. 3) 
and
snowplow-java-tracker- 2. 1. 0. jar -> snowplow-java-tracker- 2. 1. 0 (com.snowplowanalytics: snowplow- java- tracker: 2. 1. 0) 

To Reproduce

  1. Publish a pure Java library that depends on the Snowplow java-tracker to your Maven Local repo.
  2. Configure an Android application to additionally check your Maven Local repo.
repositories {
    mavenLocal()
    ... // Other repos you might need
}
  1. Add to your Android application a dependency on the library that you published in Step 1.
  2. Add to your Android application a dependency on the Snowplow android-tracker.
  3. Build application.

Expected behaviour

The Android application can be successfully compiled with both the java-tracker and the android-tracker side by side.

Additional context

I originally wanted to use the android-tracker as a dependency to the library I am building (library A) but I cannot import an Android .aar into a project that only depends on Java. The usage of Snowplow in Library A is to send events about Library A independently of whatever application Library A may be embedded in - be that Java or Android.

It looks to me that it is only DevicePlatform (in the Java tracker, in the Android tracker) that causes the issue due to the matching namespace and class name.

I really like the android-tracker compared to the java-tracker as I mainly write Kotlin, but there isn't a way for me to build a pure Java SDK that can depend on the android-tracker at the moment and I realise refactoring the android-tracker to separate Android dependencies into another artefact (perhaps two Kotlin written SDKs called snowplow-core and snowplow-android) is a bit much to ask.

As a quick win would you consider renaming DevicePlatform in the java-tracker? Or moving it to a package that won't cause a collision?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions