Nativeblocks Core
Nativeblocks is a tool for Android that helps you build your app’s screens from simple JSON files that come from your server. You don’t need to update the app for every small change in the UI — you control things from your backend instead.
What can Nativeblocks do?
- Update UI from the backend: Change what your app looks like by sending new JSON. No need to re-release your app.
- Pick how you load screens: You can use a cloud setup (everything from your server), or a community setup (you give it a set of frame URLs).
- Add actions and events: Your screens can have buttons, input, and other interactions driven by your backend.
- Works for small and big apps: Nativeblocks can be used for simple or very complex UI, and it helps keep your codebase tidy.
How does it work?
Here’s the usual flow:
- Initialization: Set up Nativeblocks in your app (your
ApplicationorActivity). - Frame Registration: The system loads the list of screen frames from the backend or your configuration.
- Rendering: Your blocks, screens, and actions show up according to your JSON config.
Getting Started
Before you begin, make sure you have:
- Kotlin 1.9.24 or later
- Android API level 26 or higher
Add Nativeblocks to Your Project
Add this to your build.gradle file:
dependencies {
implementation("io.nativeblocks:nativeblocks-android:1.6.0")
}
Set Up Nativeblocks
You need to initialize Nativeblocks before you use it, usually at the start of your app.
Cloud Edition
If you want Nativeblocks to fetch everything from your Nativeblocks cloud:
- API Url: Get it from your Nativeblocks studio after you create a new project.
- API Key: Get it from your Nativeblocks studio after you create a new project.
- DevelopmentMode: Set this to true if you want to see changes right away during development. Turn it off for production.
NativeblocksManager.initialize(
applicationContext = this,
edition = NativeblocksEdition.Cloud(
endpoint = NATIVEBLOCKS_API_URL,
apiKey = NATIVEBLOCKS_API_KEY,
developmentMode = true
)
)
Community Edition
If you want to give a load frame from your server:
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"
)
)
)
Don’t forget to clean up when your activity is destroyed:
override fun onDestroy() {
super.onDestroy()
NativeblocksManager.getInstance().destroy()
}
Show a Nativeblocks Frame
Once initialized, you can show your first Nativeblocks screen. For Jetpack Compose:
@Composable
fun ContentView() {
NativeblocksFrame(
frameRoute = "/",
routeArguments = hashMapOf(),
loading = { NativeblocksLoading() },
error = { message -> NativeblocksError(message = message) }
)
}
The core SDK itself does not have any integrations. All integrations need to be registered in the Nativeblocks integration marketplace and provided to the SDK.
Registering Custom Integrations
Nativeblocks lets you define and register your own custom pieces, like blocks, actions, and loggers:
Custom Block
Register your own block type:
NativeblocksManager.getInstance().provideBlock(
blockType = "INTEGRATION_UNIQUE_KEY_TYPE",
block = { props -> CustomBlockInstance(props) }
)
Custom Action
To add your own action logic:
NativeblocksManager.getInstance().provideAction(
actionType = "INTEGRATION_UNIQUE_KEY_TYPE",
action = CustomActionInstance()
)
NativeblocksManager.getInstance().provideActionContractor(
actionContractor = CustomActionContractorInstance()
)
Custom Logger
If you want to handle logging in your own way:
NativeblocksManager.getInstance().provideEventLogger(
loggerType = "INTEGRATION_UNIQUE_KEY_TYPE",
logger = CustomLoggerInstance()
)
Change Language
To set the language used in your screens:
NativeblocksManager.getInstance().setLocalization("EN")
Set global parameters for A/B testing
To set global parameters used to load a frame based on some conditions:
NativeblocksManager.getInstance().setGlobalParameters(
"language" to "EN",
"country" to "UAE",
"currency" to "AED",
"appVersionCode" to "45"
)
Landing api to get and show active landing page route:
NativeblocksManager.getInstance().getLanding("landing-unique-name").onSuccess { route ->
// get landing route and pass it to NativeblocksFrame
route
}
Experiment, feature-flag api to get and show active flag:
val value = NativeblocksManager.getInstance().getExperiment("flag-key", "defaultValue")
Custom Type Converter
If your JSON contains a special type (for example, a size or color), you can register a converter:
NativeblocksManager.getInstance().provideTypeConverter(
type = Dp::class,
converter = DpNativeType()
)