Android Setup
Android-specific configuration for SwiftPatch.
Requirements
- Android SDK 24+ (minSdkVersion)
- Compile SDK 34+
- Kotlin 1.9+
- CMake (a build tool for compiling native C/C++ code, used for the bsdiff native library)
Step 1: Verify Auto-Linking
The SDK auto-links via React Native CLI. No manual linking needed.
Step 2: Add Your App ID
android/app/src/main/res/values/strings.xml
<resources>
<string name="app_name">YourApp</string>
<string name="SwiftPatchAppId">YOUR_APP_ID</string>
<!-- Optional: Public key for bundle signature verification -->
<string name="SwiftPatchPublicKey">YOUR_PUBLIC_KEY</string>
<!-- Optional: Custom server URL (defaults to SwiftPatch cloud) -->
<string name="SwiftPatchServerUrl">https://your-server.com/api/v1</string>
</resources>
tip
Find your App ID in the SwiftPatch Dashboard under Settings.
Native Config Keys
| Key | Required | Description |
|---|---|---|
SwiftPatchAppId | Yes | App ID from the dashboard |
SwiftPatchServerUrl | No | Custom server URL (self-hosted only) |
SwiftPatchPublicKey | No | Public key for bundle signing |
Step 3: Update MainApplication
Kotlin (React Native 0.76+)
android/app/src/main/java/.../MainApplication.kt
import com.swiftpatch.SwiftPatchModule
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getJSBundleFile(): String? {
return SwiftPatchModule.getJSBundleFile(applicationContext)
?: super.getJSBundleFile()
}
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Add any custom packages here
}
override fun getJSMainModuleName(): String = "index"
}
}
This tells your app to load the SwiftPatch bundle in release builds instead of the default one.
Kotlin (React Native 0.82+)
android/app/src/main/java/.../MainApplication.kt
import com.facebook.react.ReactHost
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.swiftpatch.SwiftPatchModule
class MainApplication : Application(), ReactApplication {
override val reactHost: ReactHost by lazy {
getDefaultReactHost(
context = applicationContext,
packageList = PackageList(this).packages,
jsBundleFilePath = SwiftPatchModule.getJSBundleFile(applicationContext)
)
}
}
Step 4: Add ProGuard Rules (If Applicable)
If you use ProGuard or R8 (Android tools that shrink and obfuscate app code), add these rules:
android/app/proguard-rules.pro
-keep class com.swiftpatch.** { *; }
-keepclassmembers class com.swiftpatch.** { *; }
Step 5: Verify Permissions
The SDK needs internet permission (usually already included):
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
You're all set!
Troubleshooting
Build Errors
cd android && ./gradlew clean && cd ..
npx react-native run-android
CMake Errors
The SDK uses CMake for the bsdiff native library. Install it via Android Studio:
- Open Settings > Android SDK > SDK Tools
- Install CMake
Bundle Not Loading
Verify that getJSBundleFile() returns the SwiftPatch bundle path in release builds. Debug builds should use Metro (React Native's JavaScript bundler).
info
For more issues, see the full Troubleshooting guide.