Android Salesforce Mobile SDK Integration
This skill integrates the Salesforce Mobile SDK into Android Kotlin applications. It is consumed by autonomous coding agents — every reference file is self-contained and contains exact source-of-truth code, file paths, and CLI commands.
Scenarios
Pick the reference file that matches the task. Scenarios are layered: each later one assumes the previous is already wired up.
| Scenario | Reference | Preconditions |
|---|---|---|
| Create a new Android Kotlin app from scratch | references/create-new-app.md |
none |
| Add Mobile SDK authentication to an existing app | references/add-mobile-sdk.md |
Gradle Android module exists |
| Add SmartStore (encrypted local DB) | references/add-smartstore.md |
SalesforceSDKManager.initNative(...) called and bootconfig.xml exists |
| Add MobileSync (sObject ⇄ soup sync) | references/add-mobilesync.md |
SmartStoreSDKManager.initNative(...) called and userstore.json exists |
| Add Biometric Authentication (fingerprint / face / iris) | references/add-biometric-auth.md |
Mobile SDK is initialized in the Application subclass |
Cross-cutting references:
| Topic | Reference |
|---|---|
| API class map (manager hierarchy, key types) | references/api-reference.md |
| Build / login / SmartStore / sync / biometric error symptoms | references/troubleshooting.md |
Detection Rules
When the user request is ambiguous, run these checks against the working directory and pick the first scenario in the list below whose precondition is not met — even if the user asked for a later capability (e.g. a "sync" request lands on add-smartstore.md if userstore.json is not yet present, then chains forward):
- No
settings.gradle.ktsorbuild.gradle.ktsat the repo root →create-new-app.md. - Gradle module exists, but no
import com.salesforce.androidsdk.*(or any SDK class) anywhere in*.kt→add-mobile-sdk.md. - SDK initialized, but no
app/src/main/res/raw/userstore.json→add-smartstore.md. userstore.jsonexists, but nousersyncs.jsonnext to it →add-mobilesync.md.- Biometric requested but no
BiometricManagerreference and nobiometricAuthenticationManagercall →add-biometric-auth.md.
Invariants Across All Scenarios
- Manager class hierarchy (each subclasses the previous):
SalesforceSDKManager←SmartStoreSDKManager←MobileSyncSDKManager. Each scenario'sinitNative(...)call uses the lowest manager that covers the modules in use. The base scenario usesSalesforceSDKManager; SmartStore swaps toSmartStoreSDKManager; MobileSync swaps toMobileSyncSDKManager. Each swap is additive — nothing is lost. - Maven artifact follows the manager. Base scenario:
com.salesforce.mobilesdk:SalesforceSDK. SmartStore:com.salesforce.mobilesdk:SmartStore. MobileSync:com.salesforce.mobilesdk:MobileSync. Each artifact transitively pulls the lower ones — do not pre-emptively pullMobileSyncfor an app that only needs base auth. Applicationsubclass is mandatory:<Manager>.initNative(applicationContext, MainActivity::class.java)must run fromApplication.onCreate()before any SDK class is touched. Register the subclass withandroid:name=".MainApplication"inAndroidManifest.xml.MainActivityextendsSalesforceActivity: the SDK manages the OAuth/login lifecycle through this base class. OverrideonResume(client: RestClient?)fromSalesforceActivityInterfacefor post-login logic — the SDK calls it once aRestClientis available (or withnullwhen no user is currently authenticated).- Resource folders:
userstore.jsonandusersyncs.jsonmust live underapp/src/main/res/raw/. The SDK resolves them by Android resource name. - Login host: configured via
app/src/main/res/xml/servers.xml.https://login.salesforce.comis production;https://test.salesforce.comis sandboxes. - Do not recreate Gradle scaffolding for an existing app. When adding the SDK to an existing project, only modify
app/build.gradle.kts,AndroidManifest.xml, andMainActivity.kt, and create the new files (MainApplication.kt,bootconfig.xml,servers.xml,strings.xml). Do not overwritegradle.properties,settings.gradle.kts, rootbuild.gradle.kts, orgradle-wrapper.properties— those belong to "Create New App" only. - Build target:
./gradlew assembleDebugfrom the project root unless the agent has reason to use a different variant.
Source of Truth
When the SDK API in this skill disagrees with reality, the upstream Kotlin/Java in https://github.com/forcedotcom/SalesforceMobileSDK-Android wins.