This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the Superwall Android SDK - an open-source framework for remotely configuring paywalls and managing subscriptions in Android apps. The SDK provides a WebView-based paywall system with server-side configuration, A/B testing, and comprehensive analytics.
# Build the project
./gradlew build
# Run unit tests
./gradlew test
# Run instrumentation tests (requires connected device/emulator)
./gradlew :app:connectedCheck
# Run integration tests with screenshot recording
./gradlew :app:connectedCheck -Pdropshots.record
# Build and publish SDK locally
./gradlew publishToMavenLocal
# Generate build info
./gradlew generateBuildInfo# Run linting (if available)
./gradlew lint
# Run code formatting (if available)
./gradlew ktlintFormat- Unit tests:
./gradlew :superwall:test - Integration tests:
./gradlew :app:connectedCheck - Screenshot tests use Dropshot library for UI regression testing
- Tests require API 33 Pixel 7 emulator for consistent screenshot results
Main SDK Entry Point: superwall/src/main/java/com/superwall/sdk/Superwall.kt
- Singleton configuration through
Superwall.configure() - Requires
Application,apiKey, optionalPurchaseController,SuperwallOptions,ActivityProvider - Creates
DependencyContainerwhich orchestrates all components
Dependency Container: superwall/src/main/java/com/superwall/sdk/dependencies/DependencyContainer.kt
- Central dependency injection container
- Implements multiple factory interfaces for clean separation
- Manages component lifecycle and inter-dependencies
Key Managers:
ConfigManager: Fetches and caches remote configuration with retry logicIdentityManager: Handles user identity, attributes, and anonymous usersStoreManager: Manages Google Play Billing integration and product fetchingPaywallManager: Handles paywall presentation, caching, and lifecycle
Presentation Flow:
Superwall.register()- Registers placement eventsTrackingLogic.canTriggerPaywall()- Evaluates trigger conditionsPaywallPresentationHandler- Manages presentation logicPaywallView- Custom FrameLayout hosting WebView-based paywalls
Rule Evaluation: superwall/src/main/java/com/superwall/sdk/paywall/presentation/rule_logic/
- CEL (Common Expression Language) evaluator for complex rules
- JavaScript fallback for rule evaluation
- User/device attribute matching for targeting
Transaction Management: superwall/src/main/java/com/superwall/sdk/store/transactions/TransactionManager.kt
- Supports internal paywall purchases, external purchases, and observer mode
- Google Play Billing wrapper with connection lifecycle management
- Purchase state tracking and restoration functionality
Purchase Sources:
Internal: Purchases from within paywallsExternalPurchase: Direct API purchasesObserverMode: Tracking external purchases
Local Storage: superwall/src/main/java/com/superwall/sdk/storage/LocalStorage.kt
- SharedPreferences for configuration caching
- SQLite (Room) for complex data storage
- Multi-layer caching strategy (memory, disk, network)
Cache Types:
- Config caching with refresh mechanisms
- Paywall content and asset caching
- Product caching to reduce API calls
- A/B test assignment persistence
Event System: superwall/src/main/java/com/superwall/sdk/analytics/internal/Tracking.kt
- Comprehensive event tracking with internal and user-initiated events
- Session management and device classification
- Event queuing for batch network transmission
- Delegate notification system for custom event handling
SuperwallDelegate: Primary interface for SDK events and lifecycle callbacks
handleSuperwallEvent(): All Superwall eventssubscriptionStatusDidChange(): Subscription state changeswillPresentPaywall()/didPresentPaywall(): Paywall lifecyclehandleCustomPaywallAction(): Custom paywall actions
PurchaseController: Custom purchase handling interface
purchase(): Handle purchase requestsrestorePurchases(): Handle restoration- Supports both automatic and manual purchase flows
Superwall.register(): Register placement eventsSuperwall.identify(): User identificationSuperwall.setUserAttributes(): User property managementSuperwall.purchase(): Direct purchase APISuperwall.restorePurchases(): Restore functionality
- superwall/: Main SDK module
- superwall-compose/: Jetpack Compose integration
- app/: Demo app with integration tests
- example/: Example implementations with different configurations
- buildSrc/: Build configuration and scripts
- Extensive use of Kotlin Coroutines with proper scoping
IOScopefor network operations,MainScopefor UI updates- Thread-safe operations using single-threaded executors where needed
- Modular service architecture with retry mechanisms
- Environment-specific endpoints and configuration
- Request/response factories for type safety
- Comprehensive error tracking and recovery mechanisms
- Graceful degradation when network/services are unavailable
- User-facing error messages through delegate system
- No hardcoded API keys or secrets in source code
- Secure handling of purchase verification
- Proper ProGuard rules for release builds
- Located in
src/test/directories - Mock-based testing using MockK
- Use Given/When/Then DSL (
com/superwall/sdk/utils.kt) - Focus on business logic and data transformations
- Located in
app/src/androidTest/ - Real device/emulator testing
- Use Given/When/Then DSL (
superwall/src/androidTest/java/utils.kt) - Screenshot regression testing with Dropshot
- End-to-end paywall presentation and purchase flows
- Tests require connected Android device or emulator
- Pixel 7 API 33 recommended for consistent results
- Test orchestrator used for reliable test execution
- Factory pattern implementation through
DependencyContainer - Interface-based design for testability
- Lazy initialization where appropriate
- Coroutines with structured concurrency
- Flow-based reactive programming
- Proper cancellation and timeout handling
- MainScope and IoScope custom wrappers
- Remote configuration with local fallbacks
- Versioning and migration support
- Feature flags for gradual rollouts
- Immutable data classes for state representation
- Event-driven state transitions
- Proper lifecycle management for Android components