A library for remote logging, database debugging, shared preferences and network requests
Android Remote Debugger is a library for remote debugging Android applications. It allows you to view logs, databases, shared preferences and network requests directly in the browser.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the following dependency to your module's build.gradle:
dependencies {
debugImplementation 'com.github.zerobranch.android-remote-debugger:debugger:1.1.2'
releaseImplementation 'com.github.zerobranch.android-remote-debugger:noop:1.1.2'
}
Note: The final line above will use a no-op version, which does nothing. It should only be used in production build. This makes it impossible to run the server on a production build.
Android Remote Debugger has 4 sections:
For the Logging
, Database
and Shared Preferences
sections to work, several steps are necessary:
Call: AndroidRemoteDebugger.init(applicationContext)
in the application code.
After launching your application, you will receive a notification in the notification panel, in which a link of the type: http://xxx.xxx.x.xxx:8080 will be indicated. Just follow this link in your browser. Also, an entry will be added to logcat: D/AndroidRemoteDebugger: Android Remote Debugger is started. Go to: http://xxx.xxx.x.xxx:8080
To view the logs in the Logging
section, you must call the static methods AndroidRemoteDebugger.Log
anywhere in your application, for example, AndroidRemoteDebugger.Log.d("tag", "message")
or AndroidRemoteDebugger.Log.log(priority, tag, msg, throwable)
with all parameters specified.
To view network logs in the Network
section, it is necessary to use the OkHttp3 library and add the NetLoggingInterceptor
interceptor. Recommended to add it after all others interceptors to get actual network traffic data.
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new NetLoggingInterceptor())
.build();
Attention
adb forward tcp:8080 tcp:8080
and go to the address:
http://localhost:8080 or http://0.0.0.0:8080 in your browser.To configure the library, use AndroidRemoteDebugger.Builder
AndroidRemoteDebugger.init(
new AndroidRemoteDebugger.Builder(applicationContext)
.enabled(boolean)
.disableInternalLogging()
.enableDuplicateLogging()
.disableJsonPrettyPrint()
.disableNotifications()
.excludeUncaughtException()
.port(int)
.build()
);
AndroidRemoteDebugger.Builder
parametersAll parameters for AndroidRemoteDebugger.Builder
are optional. For standard library operation, just call AndroidRemoteDebugger.init(applicationContext)
.
.enabled(boolean) - library enable control
.disableInternalLogging() - disable internal logs of Android Remote Debugger
.disableJsonPrettyPrint() - disable pretty print json in `Logging` and` Network` sections
.disableNotifications() - disable Android Remote Debugger status notifications
.excludeUncaughtException() - exclude log printing when application crashes
.port(int) - use a different port than 8080
.enableDuplicateLogging() - all logs from `Logging` section will also be printed in logcat
.enableDuplicateLogging(new Logger() { - callback to get all logs from `Logging` section
@Override
public void log(int priority, String tag, String msg, Throwable th) {
}
})
The NetLoggingInterceptor
interceptor has two constructors: empty and with a callback to get all logs from Network
section
new NetLoggingInterceptor(new NetLoggingInterceptor.HttpLogger() {
@Override
public void log(HttpLogModel httpLogModel) {
}
})
adb forward tcp:8081 tcp:8081
.If you use R8, you don't have to do anything. The specific rules are included automatically.
If you don't use R8 you have to apply the following rules:
-keep class zerobranch.androidremotedebugger.source.models.** { *; }
-keep class zerobranch.androidremotedebugger.source.local.LogLevel
You might also need rules from OkHttp3 and Gson, which are dependencies of this library.
Copyright 2020 Arman Sargsyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.