Usage: SDK initialization
Set your credentials and get authorization of usage.
Initialize
Create an instance of RookConfigurationManager providing a context:
val rookConfigurationManager = RookConfigurationManager(context)
Set a configuration and initialize. The RookConfiguration requires the following parameters:
- clientUUID
- secretKey
- environment
val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val configuration = RookConfiguration(clientUUID, secretKey, environment)
// Enable logging only on debug builds
if (BuildConfig.DEBUG) {
rookConfigurationManager.enableLocalLogs()
}
rookConfigurationManager.setConfiguration(configuration)
rookConfigurationManager.initRook().fold(
{
// Success
},
{
// Handle error
}
)
Recommendations
You should only initialize the SDK once per app launch. We recommend using the RookConfigurationManager as a singleton
with a ServiceLocator or with dependency injection.
<!--AndroidManifest.xml-->
<application
android:name=".RookApplication">
</application>
class RookApplication : Application() {
lateinit var serviceLocator: ServiceLocator
override fun onCreate() {
super.onCreate()
serviceLocator = ServiceLocator(applicationContext)
}
}
class ServiceLocator(context: Context) {
val rookConfigurationManager: RookConfigurationManager by lazy {
RookConfigurationManager(context).apply {
val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val rookConfiguration = RookConfiguration(CLIENT_UUID, SECRET_KEY, environment)
if (BuildConfig.DEBUG) {
enableLocalLogs() // MUST be called first if you want to enable native logs
}
setConfiguration(rookConfiguration)
}
}
}