How vkcom/vk-android-sdk works
Project Type and Purpose
• This is an Android SDK library (multi‑module Gradle project) providing:
• Core network + auth framework (“core” module)
• Generated VK API service stubs + DTOs (“api” module)
• Host support for in‑app/browser OAuth flows (“host” module)
• User‑ID helper functionality (“id” module)
• Sample Android application demonstrating integration (“samples/app”).
• Its purpose is to let Android apps authenticate with VK, call VK’s REST API, handle token refresh, parse JSON responses, and upload files.
Main Components
• Sample Application (Android APK)
• Core SDK module
• HTTP client (OkHttp)
• API call scheduler, retry/chain logic
• JSON parsing, token management, preferences storage
• API SDK module
• Auto‑generated service classes (e.g., FriendsService, PhotosService)
• DTOs for request/response payloads
• Host SDK module
• OAuth launcher activities/components
• WebView or deep‑link handler for VK app
• ID SDK module
• UserId utilities, Gson serializers
• External VK Backend (REST API endpoints)
• External OAuth providers (VK App, Browser)
Relationships and Data Flows
• The Sample App depends on Core, API, Host, and ID modules.
• Authentication Flow:
Sample App → Host SDK → Android OS (WebView or VK App) → OAuth login UI → callback → Host SDK → Core SDK (token stored) → Sample App.
• API Call Flow:
Sample App → API SDK (service.method(...)) → Core SDK (VKApiManager) → HTTP client → VK Backend → JSON response → Core SDK JSON parser → API DTO parser → Sample App callback.
• Token Expiry: Core SDK issues callbacks to registered VKTokenExpiredHandler in the Sample App.
Architectural Patterns and Principles
• Modular layered architecture:
• Core layer abstracts networking & auth.
• API layer contains only service stubs and models.
• Host and ID layers extend core for specific features.
• Dependency Injection (via Gradle & Interface abstractions)
• Chain of Responsibility for error handling and retries
• Separation of concerns: UI auth handled in Host, business logic in Core, API model definitions in API.