Skip to content

Instantly share code, notes, and snippets.

@pandulapeter
Last active April 12, 2024 15:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandulapeter/3f9b404d953c6d80ed8a19eb06db4541 to your computer and use it in GitHub Desktop.
Save pandulapeter/3f9b404d953c6d80ed8a19eb06db4541 to your computer and use it in GitHub Desktop.
Advanced setup instructions for Beagle
// 1. In the project-level build.gradle file
buildscript {
...
ext {
...
beagleVersion = "2.9.4" // Check GitHub (https://github.com/pandulapeter/beagle/releases) / MavenCentral (https://repo1.maven.org/maven2/io/github/pandulapeter/beagle/) for the latest version
beagleUiType = "ui-drawer" // Could also be "ui-activity", "ui-bottom-sheet", "ui-dialog" or "ui-view"
}
}
allprojects {
...
repositories {
...
mavenCentral()
}
}
// 2. In the "app" module's build.gradle file
dependencies {
...
debugImplementation "io.github.pandulapeter.beagle:$beagleUiType:$beagleVersion" // For all build types where Beagle is needed
releaseImplementation "io.github.pandulapeter.beagle:noop:$beagleVersion" // For production releases
// Add the following if you need the crash logging feature:
debugImplementation "io.github.pandulapeter.beagle:log-crash:$beagleVersion" // For all build types where crash logging is needed
releaseImplementation "io.github.pandulapeter.beagle:log-crash-noop:$beagleVersion" // For production releases / build types with a better crash reporting solution
// If you decide to use crash logging, please read this section: https://github.com/pandulapeter/beagle#displaying-crash-logs
}
// 3A. If you don't have a separate "data" module, simply add the following to the "app" module's build.gradle file
dependencies {
...
debugImplementation "io.github.pandulapeter.beagle:log-okhttp:$beagleVersion" // For all build types where Beagle is needed
releaseImplementation "io.github.pandulapeter.beagle:log-okhttp-noop:$beagleVersion" // For production releases
}
// 3B. If you have a "data" module that depends on the Android SDK, add the following to its build.gradle file
dependencies {
...
debugApi "io.github.pandulapeter.beagle:log:$beagleVersion" // For all build types where Beagle is needed
releaseApi "io.github.pandulapeter.beagle:log-noop:$beagleVersion" // For production releases
debugApi "io.github.pandulapeter.beagle:log-okhttp:$beagleVersion" // For all build types where Beagle is needed
releaseApi "io.github.pandulapeter.beagle:log-okhttp-noop:$beagleVersion" // For production releases
}
// 3C. If you have a pure Kotlin "data" module that does not depend on the Android SDK, add the following to its build.gradle file
dependencies {
...
api "io.github.pandulapeter.beagle:log:$beagleVersion"
api "io.github.pandulapeter.beagle:log-okhttp:$beagleVersion"
}
// 4. Initialize the library in the onCreate() method of your custom Application class
Beagle.initialize(
application = this,
appearance = Appearance(
themeResourceId = R.style.DebugMenuTheme // Only add this if you have issues with the defaults. If you do, extend one of the ".NoActionBar" Material themes
// Check the constructor for other optional parameters you might find useful
),
behavior = Behavior(
logBehavior = Behavior.LogBehavior(
loggers = listOf(BeagleLogger) // Only needed if you have more than one modules (cases 3B or 3C from above)
),
networkLogBehavior = Behavior.NetworkLogBehavior(
baseUrl = BuildConfig.BASE_URL, // Just to reduce duplicated information in log previews
networkLoggers = listOf(BeagleOkHttpLogger)
),
bugReportingBehavior = Behavior.BugReportingBehavior(
crashLoggers = listOf(BeagleCrashLogger), // Only if you have added the "log-crash" dependency above. Note: this will probably conflict with other crash reporting solutions
logRestoreLimit = 20, // By default this is 20. Decrement the value if the crash reporter feature does not work (!!! FAILED BINDER TRANSACTION !!! error - transaction too large). This is needed if the app has huge logs / network logs.
buildInformation = {
listOf(
"Version name".toText() to BuildConfig.VERSION_NAME,
"Version code".toText() to BuildConfig.VERSION_CODE.toString(),
"Application ID".toText() to BuildConfig.APPLICATION_ID
)
}
// Check the constructors for other optional parameters you might find useful
)
)
)
// 5. Set up the initial module configuration (again, in the Application's onCreate() method, after initializing)
Beagle.set(
HeaderModule(
title = getString(R.string.app_name),
subtitle = BuildConfig.APPLICATION_ID,
text = "${BuildConfig.BUILD_TYPE} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
),
AppInfoButtonModule(),
DeveloperOptionsButtonModule(),
PaddingModule(),
TextModule("General", TextModule.Type.SECTION_HEADER),
KeylineOverlaySwitchModule(),
AnimationDurationSwitchModule(),
ScreenCaptureToolboxModule(),
DividerModule(),
TextModule("Logs", TextModule.Type.SECTION_HEADER),
NetworkLogListModule(),
LogListModule(), // Use Beagle.log() or BeagleLogger.log() to push messages
LifecycleLogListModule(),
DividerModule(),
TextModule("Other", TextModule.Type.SECTION_HEADER),
DeviceInfoModule(),
BugReportButtonModule(),
ForceCrashButtonModule()
)
// 6. To intercept network events using OkHttp, set the interceptor on the OkHttpClient builder:
val client = OkHttpClient.Builder()
.apply { (BeagleOkHttpLogger.logger as? Interceptor?)?.let { addInterceptor(it) } } // Make sure it's the last interceptor so that it can intercept everything that came before
.build()
// That's it. Don't forget that just like the Appearance and Behavior classes from the Beagle.initialize() function, Modules also have optional constructor parameters that can be used to customize them.
// You can also use Beagle.set() or Beagle.add() any time to change the configuration, just be aware that the module list is always distinct by the module ID (which, by default is a random string for most Modules).
// To see the list of all the Modules you can use, go to this link: https://github.com/pandulapeter/beagle/tree/master/common/src/main/java/com/pandulapeter/beagle/modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment