설치 및 설정
Android 프로젝트에 Dari 추가하기
의존성 추가
앱 모듈의 build.gradle.kts에 의존성을 추가합니다:
dependencies {
debugImplementation("io.github.easyhooon:dari:1.6.0")
releaseImplementation("io.github.easyhooon:dari-noop:1.6.0")
}dari-noop 모듈은 모든 공개 API의 빈 구현을 제공하여 릴리즈 빌드에서도 코드가 컴파일되며, 런타임 오버헤드가 전혀 없습니다.
초기화
Dari는 AndroidX Startup으로 자동 초기화됩니다. 설정을 바꾸고 싶을 때만 Application 클래스에서 Dari.init()을 호출합니다:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
Dari.init(
context = this,
config = DariConfig(
showNotification = true,
shakeToOpen = true,
)
)
}
}기본 설정을 사용할 때는 초기화 코드를 작성하지 않아도 됩니다.
브릿지 연결
디버그와 릴리즈 빌드에서 같은 코드가 컴파일되도록 Dari.createInterceptor()로 인터셉터를 생성합니다:
val interceptor = Dari.createInterceptor(tag = "MyBridge")각 브릿지 지점에서 인터셉터 메서드를 호출합니다. 릴리즈 빌드에서는 dari-noop이 null을 반환하므로 safe call을 사용합니다:
// Web → App: 요청 수신
interceptor?.onWebToAppRequest(
handlerName = "getUserInfo",
requestId = "req_001",
requestData = """{"userId": 123}""",
)
// Web → App: 응답 전송
interceptor?.onWebToAppResponse(
handlerName = "getUserInfo",
requestId = "req_001",
responseData = """{"name": "John"}""",
isSuccess = true,
)