Init SDK
Add and initialize the Nativeblocks SDK in your Android or iOS project.
Add the Dependency
Root settings.gradle:
settings.gradle
repositories {
mavenCentral()
}
Module build.gradle:
build.gradle
dependencies {
implementation("io.nativeblocks:nativeblocks-android:1.8.1")
}
Initialize
Call NativeblocksManager.initialize in your Application class so it is ready before any Activity starts.
Cloud Edition
App.kt
class App : Application() {
override fun onCreate() {
super.onCreate()
NativeblocksManager.initialize(
applicationContext = this,
edition = NativeblocksEdition.Cloud(
endpoint = BuildConfig.NATIVEBLOCKS_API_URL,
apiKey = BuildConfig.NATIVEBLOCKS_API_KEY,
developmentMode = BuildConfig.DEBUG
)
)
}
}
Community Edition
Load frames from your own server:
App.kt
NativeblocksManager.initialize(
applicationContext = this,
edition = NativeblocksEdition.Community(
framesData = mapOf(
"/login" to "https://api.example.com/login.json",
"/profile" to "https://api.example.com/profile.json"
)
)
)
Multi-Instance
NativeblocksManager.initialize(
name = "main",
applicationContext = this,
edition = NativeblocksEdition.Cloud(...)
)
val manager = NativeblocksManager.getInstance("main")
Destroy
Clean up when your app terminates.
MainActivity.kt
override fun onDestroy() {
super.onDestroy()
NativeblocksManager.getInstance().destroy()
}
Global Parameters
Global parameters are sent with every frame request and used for A/B test targeting and conditional rendering:
NativeblocksManager.getInstance().setGlobalParameters(
"language" to Locale.getDefault().language,
"country" to Locale.getDefault().country,
"appVersionCode" to BuildConfig.VERSION_CODE.toString(),
"plan" to "pro"
)
Full Example
A complete setup using an Application class and a single-Activity Compose app.
App.kt
class App : Application() {
override fun onCreate() {
super.onCreate()
NativeblocksManager.initialize(
applicationContext = this,
edition = NativeblocksEdition.Cloud(
endpoint = BuildConfig.NATIVEBLOCKS_API_URL,
apiKey = BuildConfig.NATIVEBLOCKS_API_KEY,
developmentMode = BuildConfig.DEBUG
)
)
NativeblocksManager.getInstance().setGlobalParameters(
"language" to Locale.getDefault().language,
"country" to Locale.getDefault().country,
"appVersionCode" to BuildConfig.VERSION_CODE.toString()
)
}
}
MainActivity.kt
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyAppTheme {
NativeblocksFrame(
route = "/home",
routeArguments = hashMapOf(),
loading = { NativeblocksLoading() },
error = { message -> NativeblocksError(message = message) }
)
}
}
}
override fun onDestroy() {
super.onDestroy()
NativeblocksManager.getInstance().destroy()
}
}