Android build fails under AGP 9 when analytics-kotlin is also in the dependency graph: duplicate namespace 'com.segment.analytics'

Open Beginner friendly
#214 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, dart, flutter

Research direction

Inspect the plugin's Android module and AndroidManifest.xml, then reproduce the failure with flutter build apk --debug using segment_analytics and com.segment.analytics.kotlin:android. Compare the namespace and package declarations with the issue's proposed unique namespace, and verify that the Android build completes without the duplicate-namespace error.

Written by the indexing model from the issue text.

Description

The plugin's Android module declares namespace 'com.segment.analytics' — the same namespace as Segment's native Android SDK (com.segment.analytics.kotlin:android, whose AAR manifest declares package="com.segment.analytics"). AGP 9 treats duplicate namespaces as a hard manifest-merger error, so any app that has both in its dependency graph no longer builds. This happens in practice with SDKs that embed analytics-kotlin, e.g. the Customer.io SDK (customer_ioio.customer.android:datapipelinescom.segment.analytics.kotlin:android).

Steps to reproduce

  1. Flutter app with segment_analytics: 1.1.12 and AGP 9.x (tested with 9.1.0).
  2. Add the native SDK to android/app/build.gradle (or any dependency that pulls it in, e.g. customer_io):
    dependencies {
        implementation "com.segment.analytics.kotlin:android:1.24.1"
    }
    
  3. flutter build apk --debug

Result

[:segment_analytics] .../merged_manifest/debug/processDebugManifest/AndroidManifest.xml Error:
	Namespace 'com.segment.analytics' is used in multiple modules and/or libraries: :segment_analytics, com.segment.analytics.kotlin:android:1.24.1. Please ensure that all modules and libraries have a unique namespace.

Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed with multiple errors, see logs

Fix

Rename the plugin's namespace to something unique, e.g. com.segment.analytics.flutter, and drop the deprecated package= attribute from AndroidManifest.xml. The namespace only affects the generated R/BuildConfig package, not the Dart API or Kotlin source packages. We've been running this patch in production: https://github.com/cheddar-me/analytics_flutter/commit/dda9906f4c3aed3c0b220f3c99447fafa2c3ddb8

Dominant language
Dart
Stars
33
Forks
57
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from segmentio/analytics_flutter

All issues in segmentio/analytics_flutter

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.