:library:core:common

Purpose

Holds low-level contracts, domain result types, host configuration, dispatchers, constants, and Android utility abstractions shared across the toolkit.

Owns

  • AdsSettingsRepository and OnboardingRepository, SDK-neutral contracts consumed across modules.

  • BuildInfoRepository and its DefaultBuildInfoRepository, backed by the host build configuration.

  • InstalledAppsRepository and its system-backed default own single/batch installation checks, AppInstallInfo with shared AppVersionMetadata, launcher intents, and API 33+ launch tokens. Every lookup is main-safe; the repository owns the IO switch and keeps cancellation intact.

  • AdMobAppIdDataSource and ManifestAdMobAppIdDataSource in data/local: the shared host manifest contract and its cached, main-safe platform implementation.

  • Analytics and billing value models, and the application-facing theme preference model.

  • ClipboardRepository and its system-backed DefaultClipboardRepository, so a ViewModel copies text without holding a Context. It also says whether the system confirms copies itself.

  • The failures the data layer throws: NetworkException and StorageException, each with a reason. Translating into them belongs to :library:core:network and :library:core:datastore, and the text a screen shows for them to :library:core:ui.

  • The vendor-neutral telemetry contracts in core.common.telemetry, split by responsibility: AnalyticsReporter (GA4 events, screen views, user properties), DiagnosticsReporter (breadcrumbs and non-fatal reports) and TelemetryCollection (the consent-driven collection switches). TelemetryRepository is all three, for the UI layer; telemetryModule binds the three to the app's one TelemetryRepository. The analytics models are in telemetry.models, with TrackedScreen, the stable name and class of a screen that ScreenHost reports.

  • BillingCore, dispatcher, build-info, app-info, permissions, and ad-SDK contracts.

  • Host DI configuration (AppToolkitHostBuildConfig, qualifiers, and constants).

  • Small platform and Kotlin extensions used across modules. An extension or constant that one module uses lives in that module instead: FAQ, changelog, issue reporter, billing, ads and review each own theirs.

  • The Play Integrity license-check manifest permission required by the shared App Check setup.

  • The App Name placeholders for app_name and app_full_name, plus the default copyright resource used by toolkit UI. A host replaces the name resources with its application identity.

Does not own

  • DataStore implementations, owned by :library:core:datastore.

  • HTTP clients and network error mapping, owned by :library:core:network.

  • Compose state and components, owned by :library:core:ui.

  • Firebase and Billing SDK implementations, owned by their integration modules.

Depends on

No internal Gradle modules. This is the bottom shared runtime dependency for most toolkit modules.

Used by

  • :sample and :library:apptoolkit for host and toolkit contracts.

  • :library:core:datastore, :library:core:network, :library:core:ui, and :library:core:designsystem.

  • :library:feature:about, :library:feature:faq, :library:feature:issuereporter, :library:feature:onboarding, :library:feature:permissions, :library:feature:settings, :library:feature:startup, and :library:feature:support.

  • :library:integration:ads, :library:integration:billing, :library:integration:consent, :library:integration:firebase, :library:integration:review, and :library:integration:update.

:library:navigation also depends on this module for shared sizing constants. The implicit :library:core parent has no dependencies.

Flow chart

flowchart TD
    Host[Host application] --> Config[AppToolkitHostBuildConfig]
    Android[Android platform] --> Helpers[App / permission / text helpers]
    Config --> Contracts[SDK-neutral contracts and qualifiers]
    Helpers --> Contracts
    Dispatchers[DispatcherProvider] --> Consumers[Core, feature, integration, and navigation modules]
    Contracts --> Consumers
    Models[Theme / analytics / billing values] --> Consumers
    Consumers --> Implementations[Datastore, Firebase, Billing, UI implementations]
    Implementations -. implement .-> Contracts

Architectural decisions

  • Analytics belong to the UI layer; diagnostics belong everywhere. Code under data/ and domain/ takes DiagnosticsReporter, and TelemetryCollection where it applies consent, never AnalyticsReporter or TelemetryRepository. A repository returns its outcome, and the screen or ViewModel that asked reports the product event. Breadcrumbs and non-fatal reports stay in repositories, because a background failure that never reaches a screen still has to be seen. checkModuleBoundaries enforces this, with :library:integration:firebase as the one module allowed to name analytics from its data layer, because it implements them.

  • common is the lowest shared production boundary, so it defines narrow SDK-neutral contracts while concrete Firebase, Billing, persistence, and UI implementations live above it.

  • Android helpers remain behind small interfaces when tests or host substitution need a boundary; pure constants and extensions stay concrete.

  • Shared models are added only when two layers genuinely exchange the same value. Persistence and presentation-specific representations remain in their owning modules.

  • The manifest AdMob ID is the only ads identity source; a library fallback would silently bind a host to the wrong publisher account.

Package version metadata

AppVersionMetadata and PackageManager.getVersionMetadata expose nullable version names and long version codes without a UI model. Issue Reporter and the sample installed-app source share this lookup. Unavailable, hidden, or unreadable packages return null. getVersionMetadata is a blocking PackageManager call, so data-layer callers switch to dispatchers.io around it.

Public contracts

  • TelemetryRepository, AnalyticsReporter, DiagnosticsReporter, TelemetryCollection, telemetryModule, BillingCore, DispatcherProvider, and provider/helper interfaces.

  • AppToolkitHostBuildConfig, DI qualifiers, common result/value models, and stable constants.

  • core.common.data.models.theme.ThemePreferencesState, the immutable application-facing representation shared by persistence and theme UI.

Internal implementations

  • StandardDispatchers, AppToolkitApplication, small Android adapters, extensions, and crash guards.

Current risks

The module has a broad surface spanning domain values, Android helpers, DI metadata, ads, billing, and Firebase contracts. That breadth makes it easy for unrelated concerns to accumulate in the lowest-level dependency.

Migration notes

The commented DataStore dependency in the Gradle file records that common -> datastore was removed to break a circular dependency. Keep persistence implementations above the contracts defined here.

Host AdMob ID and UMP crash guard

The toolkit once shipped a demo R.string.ad_mob_app_id. A host using a differently named resource did not override it, so consent and Mobile Ads initialization could silently target the demo publisher account. The current contract deliberately prevents that regression:

  • com.google.android.gms.ads.APPLICATION_ID in the host application's manifest is the single source of truth. The referenced resource may have any name.

  • ManifestAdMobAppIdDataSource reads application metadata through PackageManager, accepts only ca-app-pub-[0-9]{16}~[0-9]{10}, and returns null for missing or malformed values.

  • There must be no library fallback AdMob application ID. The sample/demo ID belongs only to the sample application.

  • Hosts should let the :library:integration:ads AppOpenAdController initialize Mobile Ads; separate initialization with another ID can recreate the mismatch.

UMP 4.0.0 can also throw NoSuchElementException from Scanner.next() on its executor when a metrics error response has an empty body. ConsentSdkCrashGuard is installed by AppToolkitApplication immediately after Firebase initialization so it wraps the Crashlytics handler. It suppresses only a non-main-thread NoSuchElementException whose stack contains both java.util.Scanner and com.google.android.gms.internal.consent_sdk; every other throwable is delegated unchanged. The suppressed telemetry failure is recorded through DiagnosticsReporter.recordNonFatal.

Hosts may opt out by overriding installsConsentSdkCrashGuard with false. Do not broaden the guard predicate, and do not remove the guard until the affected UMP artifact behavior is verified as fixed. AdMobAppIdDataSourceTest and ConsentSdkCrashGuardTest protect these contracts.

Data API migration

BuildInfoProvider is replaced by data.repositories.BuildInfoRepository; its properties still represent the host's fixed build values, with no platform I/O. The Toolkit graph supplies the default.

AdMobAppIdProvider and its manifest implementation are replaced by data.local.AdMobAppIdDataSource and ManifestAdMobAppIdDataSource. Reading the ID is now suspending so the source can own the IO switch. Hosts providing a replacement update their binding directly.

AppInfoHelper is removed. Use InstalledAppsRepository for data queries and core UI's AppLauncher when launching with the Toolkit's failure feedback.

Packages