Dari

Setup

Add Dari to your Android project

Installation

Add the dependencies to your app module's build.gradle.kts:

dependencies {
    debugImplementation("io.github.easyhooon:dari:1.7.0")
    releaseImplementation("io.github.easyhooon:dari-noop:1.7.0")
}

The dari-noop module implements the same public APIs with no-op behavior, so your code compiles in release with no runtime overhead.

Initialize

Dari starts automatically through AndroidX Startup. Call Dari.init() only when you need custom configuration:

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Dari.init(
            context = this,
            config = DariConfig(
                showNotification = true,
                shakeToOpen = true,
            )
        )
    }
}

If you use the default configuration, you do not need any initialization code.

Connect Your Bridge

Create an interceptor through Dari.createInterceptor() so the same app code compiles in debug and release builds:

val interceptor = Dari.createInterceptor(tag = "MyBridge")

Call the interceptor at each bridge point. In release builds, dari-noop returns null, so use safe calls:

// Web → App: request received
interceptor?.onWebToAppRequest(
    handlerName = "getUserInfo",
    requestId = "req_001",
    requestData = """{"userId": 123}""",
)

// Web → App: response sent back
interceptor?.onWebToAppResponse(
    handlerName = "getUserInfo",
    requestId = "req_001",
    responseData = """{"name": "John"}""",
    isSuccess = true,
)

On this page