Legacy — v1.1 Extension
How to install and configure the Sophonz Android SDK v1.1 with Extension support.
TIP — Add project > Add app > Obtain key
Log in to the Sophonz console, add a project under Project Management, then add an app to it with Add App. Take the issued app key from App Management, and install using the registered project name and app key.
Sophonz Android SDK Requirements
| Item | Requirement |
|---|---|
| Java version | 1.8 or higher |
| min SDK | 21 or higher (desugaring required below 26) |
| compile SDK (= target SDK) | 34 or higher |
| Support Language | Java, Kotlin |
| Gradle | 8.0 or higher |
| Gradle Plugin (AGP) | 8.0 or higher |
Installing the Sophonz Android SDK
The Sophonz SDK is designed to collect runtime data from your application. Follow the steps below to install it.
1. Gradle Configuration
The Sophonz Android SDK is distributed via a Maven repository. Add the SDK in your project's Gradle configuration files.
1-1. Project-level build.gradle or settings.gradle
When using Maven, add the repository using either Groovy or Kotlin DSL.
Groovy DSL
allprojects {
repositories {
mavenCentral()
}
}Kotlin DSL
repositories {
mavenCentral()
}1-2. Module (app) level build.gradle
When using Maven, add the Sophonz SDK to the dependencies section of your application.
Groovy DSL
dependencies {
implementation 'com.sophonz:sophonz-android-sdk:1.1.10'
}Kotlin DSL
dependencies {
implementation("com.sophonz:sophonz-android-sdk:1.1.10")
}TIP
Always use the latest SDK version.
1-3. Direct AAR installation
Create a libs directory under your application directory, copy the sophonz-android-sdk-version-release.aar file into it, then add the Sophonz SDK to the dependencies section.
Groovy DSL
dependencies {
implementation files('libs/sophonz-android-sdk-1.1.10-release.aar')
}Kotlin DSL
dependencies {
implementation(files("libs/sophonz-android-sdk-1.1.10-release.aar"))
}1-4. Desugaring
If minSdkVersion is below 26, you must enable core library desugaring.
Groovy DSL
compileOptions {
...
coreLibraryDesugaringEnabled true
}
dependencies {
// For AGP 7.4+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
// For AGP 7.3
// coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.3'
// For AGP 4.0 to 7.2
// coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.9'
}Kotlin DSL
compileOptions {
...
isCoreLibraryDesugaringEnabled = true
}
dependencies {
// For AGP 7.4+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
// For AGP 7.3
// coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.3")
// For AGP 4.0 to 7.2
// coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.9")
}2. Application Class Setup
The Sophonz SDK is initialized inside the Application class. Add the initialization code to the onCreate() method of your Application class.
- Register the Application class
Set the
android:nameattribute in yourAndroidManifest.xmlto point to yourApplicationclass. Skip this step if anApplicationclass already exists.
<application
android:name=".Application"
...
>
</application>- Write the SDK initialization code
Add the following code to the
onCreate()method of yourApplicationclass:
Kotlin
import com.sophonz.sdk.core.Sophonz
import com.sophonz.sdk.core.SophonzOption
import com.sophonz.sdk.core.Environment
class Application : android.app.Application() {
override fun onCreate() {
super.onCreate()
val options = SophonzOption()
options.setDefault()
options.setCollectorURL("Enter the collector URL here.")
options.setAppKey("Enter the app key here.")
options.setSampleRate("Enter a sampling rate (0.0–1.0).") // default=1.0
options.setProject("Namespace")
options.setRemoteCollectionControlEnable(true)
//options.setEnvironment(Environment.DEVELOPMENT)
//options.setUserEventEnable(true)
Sophonz.setup(options)
Sophonz.initialize(this.applicationContext, this)
}
}Java
import com.sophonz.sdk.core.Sophonz;
import com.sophonz.sdk.core.SophonzOption;
import com.sophonz.sdk.core.Environment;
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
SophonzOption options = new SophonzOption();
options.setDefault();
options.setCollectorURL("Enter the collector URL here.");
options.setAppKey("Enter the app key here.");
options.setSampleRate("Enter a sampling rate (0.0–1.0)."); // default=1.0
options.setProject("Namespace");
options.setRemoteCollectionControlEnable(true);
//options.setEnvironment(Environment.DEVELOPMENT);
//options.setUserEventEnable(true);
Sophonz.setup(options);
Sophonz.initialize(this.getApplicationContext(), this);
}
}setCollectorURL: URL of the server that collects data.setAppKey: The app key issued from the console.
(Settings > App Management > App Key)- (optional)
setSampleRate: Sampling rate. Default is 1.0 (100%).- Accepts a value between 0.0 and 1.0. (0.0: no collection, 1.0: 100% collection)
setProject: The namespace entered when adding the project in the dashboard.
(Project Management > Project Name) or (App Management > Project)- (optional)
setEnvironment: Deployment environment (default: .PRODUCTION) - (optional)
setUserEventEnable: Auto click event collection for XML UI (default=false) - (optional)
setRemoteCollectionControlEnable: Enable remote collection control (default=false)- The SDK applies server-side settings delivered via API.
- On/Off (default=on)
- Auto-stop policy on transmission failure (default=false)
- Failure count threshold for auto-stop policy (default=5)
3. HTTPS Configuration
- Retrofit / OkHttp
To collect XHR data from Retrofit or OkHttp network requests, add HttpInterceptor as shown below.
Kotlin
import com.sophonz.sdk.network.interceptor.HttpInterceptor
val client = OkHttpClient.Builder()
.addInterceptor(HttpInterceptor())
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()Java
import com.sophonz.sdk.network.interceptor.HttpInterceptor;
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpInterceptor())
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();- HttpURLConnection
To collect XHR data from HttpURLConnection-based network requests, wrap the connection as shown below.
Kotlin
import com.sophonz.sdk.network.urlconnection.ConnectionWrapper
// Wrap the HttpURLConnection(HttpsURLConnection) object with ConnectionWrapper
var url : URL = URL("https://some.host.com")
var conn = ConnectionWrapper.wrap(url.openConnection() as HttpURLConnection)Java
import com.sophonz.sdk.network.urlconnection.ConnectionWrapper;
// Wrap the HttpsURLConnection object with ConnectionWrapper
URL url = new URL("https://some.host.com");
HttpURLConnection conn =
ConnectionWrapper.wrap((HttpURLConnection) url.openConnection());- Ktor Configuration
3-1. Using the OkHttp engine
When using the OkHttp engine with Ktor, add the interceptor as shown below.
Kotlin
import com.sophonz.sdk.network.interceptor.HttpInterceptor
val client = HttpClient(OkHttp) {
engine {
config {
// Existing settings (timeouts, etc.)
connectTimeout(2, TimeUnit.SECONDS)
readTimeout(2, TimeUnit.SECONDS)
writeTimeout(2, TimeUnit.SECONDS)
// Add the interceptor
addInterceptor(HttpInterceptor())
}
}
install(Logging)
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true })
}
}3-2. Using the Android engine
Copy the sophonz-android-sdk-extension-version-release.aar file and add Sophonz SDK Extensions to the dependencies section.
Groovy DSL
dependencies {
implementation files('libs/sophonz-android-sdk-1.1.10-release.aar') //Sophonz SDK
//Add Sophonz SDK Extensions
implementation files('libs/sophonz-android-sdk-extensions-1.0.1-release.aar')
//implementation 'com.sophonz:sophonz-android-sdk-extensions:1.0.1' //When using Maven
}Kotlin DSL
dependencies {
implementation(files("libs/sophonz-android-sdk-1.1.10-release.aar")) //Sophonz SDK
//Add Sophonz SDK Extensions
implementation(files("libs/sophonz-android-sdk-extensions-1.0.1-release.aar"))
//implementation ("com.sophonz:sophonz-android-sdk-extensions:1.0.1") //When using Maven
}When using the Ktor Android engine, add the following to your existing client configuration to collect XHR data.
import com.sophonz.sdk.extensions.ktor.SophonzKtorIntercept
val client = HttpClient(Android) {
// Existing configuration
install(Logging)
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true })
}
// Sophonz Ktor Intercept Plugin
install(SophonzKtorIntercept.Plugin)
}4. Verification
To confirm that Sophonz is working correctly, trigger a sample error and verify that the log is transmitted. Add the following code to an appropriate location in your application.
Kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exception
import com.sophonz.sdk.log.SophonzLog
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
try {
throw Exception("Test error")
} catch (e: Exception) {
SophonzLog.error("TestTag", "This is a test error", e)
}
}
}Java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.lang.Exception;
import com.sophonz.sdk.log.SophonzLog;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
throw new Exception("Test error");
} catch (Exception e) {
SophonzLog.error("TestTag", "This is a test error", e);
}
}
}Sophonz Android SDK Configuration
Custom User ID
Set a custom user ID to identify individual users during session analysis. Typically, set it on successful login and clear it with an empty string ("") on logout. Must be called after Sophonz.initialize.
Kotlin
import com.sophonz.sdk.core.Sophonz
Sophonz.custom.setupUserId("customer-user-id")Java
import com.sophonz.sdk.core.Sophonz;
Sophonz.getCustomAttributes().setupUserId("customer-user-id");Custom Event Tracking
Send an event notification when a specific button or tab is clicked.
Sophonz.sendClickEvent(view: View, isNetworkRequest: Boolean = false)
- view: the clicked target, isNetworkRequest: whether a data request follows
For a simple screen navigation button click:
Kotlin
import com.sophonz.sdk.core.Sophonz
val intent = Intent(this, HelloActivity::class.java)
binding.button.setOnClickListener {
Sophonz.sendClickEvent(binding.button, false)
//Sophonz.sendClickEvent("button_name", false) // To pass a custom button name
startActivity(intent)
}Java
import com.sophonz.sdk.core.Sophonz;
Intent intent = new Intent(this, HelloActivity.class);
binding.button.setOnClickListener(v -> {
Sophonz.sendClickEvent(binding.button, false);
//Sophonz.sendClickEvent("button_name", false) // To pass a custom button name
startActivity(intent);
});When the button click triggers a server data request:
Kotlin
binding.button.setOnClickListener {
Sophonz.sendClickEvent(it, true)
service.getHello().enqueue(object : retrofit2.Callback<Data> {
override fun onFailure(call: Call<Data>, t: Throwable) {
t.printStackTrace()
}
override fun onResponse(call: Call<Data>, response: Response<Data>) {
response.body()?.let { data ->
SophonzLog.debug("MainActivity", "Data: $data")
}
}
})
}Java
binding.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Sophonz.sendClickEvent(v, true);
service.getHello().enqueue(new Callback<Data>() {
@Override
public void onResponse(Call<Data> call, Response<Data> response) {
Data data = response.body();
if (data != null) {
SophonzLog.debug("MainActivity", "Data: " + data.toString());
}
}
@Override
public void onFailure(Call<Data> call, Throwable t) {
t.printStackTrace();
}
});
}
});Automatic Event Instrumentation
Automatic event collection is enabled by adding options.setUserEventEnable(true). Using it alongside Sophonz.sendClickEvent() may result in duplicate events being collected. To exclude a specific View from automatic collection, set android:tag="sophonz_ignore" on that View. Text and ID collection can also be controlled via options — these settings apply to both automatic and manual events; when disabled, those values will be empty for all events (per-View configuration is not supported).
SophonzOption options = new SophonzOption();
options.setDefault();
... omitted ...
options.setUserEventEnable(true);
// Additional options
options.setUserEventTextEnable(false); // Disable Text collection (default: true) options.setUserEventIdEnable(false); // Disable ID collection (default: true)
WebView Session Bridging
To combine a native app session with a WebView page session, call JavaScriptInjector.injectSession(view) before calling webView.loadUrl(serverUrl).
TIP — Sophonz configuration in hybrid apps (WebView)
The Sophonz Android SDK, iOS SDK, and Browser SDK each collect data suited to their respective environments.
Kotlin
import com.sophonz.sdk.feature.webview.JavaScriptInjector
// ... omitted ...
JavaScriptInjector.injectSession(webView)
webView.loadUrl(serverUrl)
// ... omitted ...Java
import com.sophonz.sdk.feature.webview.JavaScriptInjector;
// ... omitted ...
JavaScriptInjector.injectSession(webView);
webView.loadUrl(serverUrl);
// ... omitted ...Cordova Library WebView Setup
When using the Cordova library, configure the WebView as follows.
Cordova Library build.gradle
compileOnly(files("libs/sophonz-android-sdk-1.1.10-release.aar"))WebView Interface Setup
Use JavaScriptInjector.injectSession(view) to connect the sessions.
protected void init() {
appView = makeWebView();
createViews();
if (!appView.isInitialized()) {
appView.init(cordovaInterface, pluginEntries, preferences);
}
cordovaInterface.onCordovaInit(appView.getPluginManager());
// Inject WebView Interface
WebView realWebView = (WebView) ((SystemWebViewEngine) appView.getEngine()).getView();
JavaScriptInjector.injectSession(realWebView);
String volumePref = preferences.getString("DefaultVolumeStream", "");
if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
}Fragment Lifecycle
Fragment lifecycle events (onCreate, onStart, onResume, etc.) are automatically instrumented to track screen entry and exit.
Screen Name Assignment
By default, the screen name is derived from f.javaClass.simpleName. If the class name is altered by obfuscation or you want to use a different name explicitly, use the @RumScreenName annotation.
import com.sophonz.sdk.annotations.RumScreenName
@RumScreenName("MyFragment")
class MyFragment : Fragment() {
...
}import com.sophonz.sdk.annotations.RumScreenName;
@RumScreenName("MyFragment")
class MyFragment extends Fragment {
...
}Obfuscation
If you are not using @RumScreenName and your project uses ProGuard/R8, add the following rule to preserve Fragment class names.
ProGuard
-keepnames class * extends androidx.fragment.app.Fragment To disable Fragment-level instrumentation entirely, set the option during initialization:
options.setFragmentLifecycleEnabled(false) Custom Logging
Use the SophonzLog API to collect custom user logs when needed. Log levels are debug, info, warn, and error.
WARNING — Custom logging caution
Use custom logging only when necessary. Excessive logging can degrade app performance and increase storage usage due to additional collected data.
TIP — Trace critical logic and transactions
Leave custom messages to identify problem patterns and exceptions in your service.
Kotlin
import com.sophonz.sdk.log.SophonzLog
SophonzLog.debug("TAG", "message")
SophonzLog.info("TAG", "message")
SophonzLog.warn("TAG", "message")
SophonzLog.error("TAG", "message", RuntimeException("exception"))Java
import com.sophonz.sdk.log.SophonzLog;
SophonzLog.debug("TAG", "message");
SophonzLog.info("TAG", "message");
SophonzLog.warn("TAG", "message");
SophonzLog.error("TAG", "message", new RuntimeException("exception"));API Reference
Sophonz
The main SDK object.
setup(option: SophonzOption): Sophonz
Configures the SDK options.
Parameters:
option: SophonzOption — SDK configuration options object
Returns:
Sophonz— Sophonz object
Kotlin
val option = SophonzOption()
option.setDefault()
option.setCollectorURL("https://in.sophonz.ai")
option.setAppKey("your-service-key")
Sophonz.setup(option)Java
SophonzOption option = new SophonzOption();
option.setDefault();
option.setCollectorURL("https://in.sophonz.ai");
option.setAppKey("your-service-key");
Sophonz.setup(option);initialize(context: Context, application: Application)
Initializes the SDK. Must be called in Application.onCreate() after setup().
Parameters:
context: Context — application contextapplication: Application — application instance
Kotlin
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val option = SophonzOption()
// ... configure options ...
Sophonz.setup(option)
Sophonz.initialize(this.applicationContext, this)
}
}Java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SophonzOption option = new SophonzOption();
// ... configure options ...
Sophonz.setup(option);
Sophonz.initialize(this.getApplicationContext(), this);
}
}sendClickEvent(view: View, isNetworkRequest: Boolean = false)
Sends a click event for a View object.
Parameters:
view: View — the clicked View objectisNetworkRequest: Boolean — whether a network request follows (default: false)
Kotlin
button.setOnClickListener { view ->
Sophonz.sendClickEvent(view, false)
}Java
button.setOnClickListener(v -> {
Sophonz.sendClickEvent(v, false);
});sendClickEvent(viewName: String, isNetworkRequest: Boolean = false)
Sends a click event with a custom name.
Parameters:
viewName: String — custom name for the click eventisNetworkRequest: Boolean — whether a network request follows (default: false)
Kotlin
button.setOnClickListener {
Sophonz.sendClickEvent("Custom Button Name", false)
}Java
button.setOnClickListener(v -> {
Sophonz.sendClickEvent("Custom Button Name", false);
});custom: CustomAttributes
The CustomAttributes object for setting user attributes.
Kotlin
Sophonz.custom.setupUserId("customer-user-id")Java
Sophonz.getCustomAttributes().setupUserId("customer-user-id");getDeviceId()
Returns the device ID.
Returns:
String— device ID
Kotlin
val deviceId = Sophonz.getDeviceId()Java
String deviceId = Sophonz.getDeviceId();getOption(): SophonzOption
Returns the currently configured SophonzOption object.
Returns:
SophonzOption— configured options object
SophonzOption
Class that manages SDK configuration.
Constructor
SophonzOption()
Creates a new SophonzOption instance.
Kotlin
val option = SophonzOption()Java
SophonzOption option = new SophonzOption();Configuration Methods
setDefault(): SophonzOption — Applies default settings.
setCollectorURL(url: String): SophonzOption — Sets the data collection server URL.
setAppKey(key: String): SophonzOption — Sets the app key.
setSampleRate(rate: Double) — Sets the sampling rate (0.0–1.0). Default is 1.0 (100%).
setProject(nameSpace: String) — Sets the project (service.namespace).
setEnvironment(environment: Environment) — Sets the deployment environment. Default is PRODUCTION.
setRemoteCollectionControlEnable(enable: Boolean) — Enables/disables remote collection control. Default is false.
setUserEventEnable(value: Boolean) — Enables/disables user click event tracking. Default is false.
setDeviceIdType(deviceIdType: DeviceIdType) — Sets the device ID type. Default is UUID.
ANDROID_ID: Converts SSAID to UUID formatUUID: Random identifier generated by the SDK (regenerated after app reinstall)
setActivityLifecycleEnabled(value: Boolean): SophonzOption — Enables/disables Activity lifecycle tracking. Default is true.
setFragmentLifecycleEnabled(value: Boolean): SophonzOption — Enables/disables Fragment lifecycle tracking. Default is true.
setDeviceIdEnable(value: Boolean) — Enables/disables device ID collection. Default is true.
setAdvancedNetworkCapture(isCapture: Boolean) — Enables/disables HTTP request body collection. Default is false.
setXhrRequestHeaderEnable(value: Boolean) — Enables/disables HTTP request header collection. Default is false.
setXhrResponseHeaderEnable(value: Boolean) — Enables/disables HTTP response header collection. Default is false.
setAnrDetectionEnable(value: Boolean) — Enables/disables ANR (Application Not Responding) detection. Default is true.
setSharedSession(flag: Boolean) — Enables/disables WebView session sharing. Default is true.
setMinSupportedApiLevel(apiLevel: Int) — Sets the minimum supported API level. Default is 21 (Android 5.0). Devices below this level will have Sophonz features disabled. Set to 26 if desugaring cannot be enabled.
CustomAttributes
Data class for setting user attributes.
setupUserId(s: String)
Sets the user ID.
Kotlin
// On login
Sophonz.custom.setupUserId("user123")
// On logout
Sophonz.custom.setupUserId("")Java
// On login
Sophonz.getCustomAttributes().setupUserId("user123");
// On logout
Sophonz.getCustomAttributes().setupUserId("");setAttribute(key: String, value: String)
Adds a custom attribute. The prefix custom. is automatically prepended to the key.
Kotlin
Sophonz.custom.setAttribute("key", "value")Java
Sophonz.getCustomAttributes().setAttribute("key", "value");removeAttribute(key: String)
Removes a custom attribute.
Kotlin
Sophonz.custom.removeAttribute("key")Java
Sophonz.getCustomAttributes().removeAttribute("key");SophonzLog
Object for sending log data.
debug / info / warn / error
Kotlin
SophonzLog.debug("MyTag", "Debug message")
SophonzLog.info("MyTag", "Info message")
SophonzLog.warn("MyTag", "Warning message")
try {
// some code
} catch (e: Exception) {
SophonzLog.error("MyTag", "Error occurred", e)
}Java
SophonzLog.debug("MyTag", "Debug message");
SophonzLog.info("MyTag", "Info message");
SophonzLog.warn("MyTag", "Warning message");
try {
// some code
} catch (Exception e) {
SophonzLog.error("MyTag", "Error occurred", e);
}Network Interceptors
HttpInterceptor
Adds a network tracking interceptor to the OkHttp client.
Kotlin
import com.sophonz.sdk.network.interceptor.HttpInterceptor
val client = OkHttpClient.Builder()
.addInterceptor(HttpInterceptor())
.build()Java
import com.sophonz.sdk.network.interceptor.HttpInterceptor;
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpInterceptor())
.build();ConnectionWrapper
Wraps HttpURLConnection for network tracking.
Kotlin
import com.sophonz.sdk.network.urlconnection.ConnectionWrapper
val url = URL("https://example.com/api")
val connection = ConnectionWrapper.wrap(url.openConnection() as HttpURLConnection)Java
import com.sophonz.sdk.network.urlconnection.ConnectionWrapper;
URL url = new URL("https://example.com/api");
HttpURLConnection connection =
ConnectionWrapper.wrap((HttpURLConnection) url.openConnection());Annotation
@RumScreenName
Annotation for assigning a screen name to a Fragment.
Kotlin
import com.sophonz.sdk.annotations.RumScreenName
@RumScreenName("CustomScreenName")
class MyFragment : Fragment() {
// ...
}Java
import com.sophonz.sdk.annotations.RumScreenName;
@RumScreenName("CustomScreenName")
class MyFragment extends Fragment {
// ...
}When the annotation is not used, the Fragment class name is used as the screen name.
Sophonz Extensions
SophonzKtorIntercept.Plugin
Adds a network tracking plugin for the Ktor Android Engine.
Kotlin
import com.sophonz.sdk.extensions.ktor.SophonzKtorIntercept
import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
val client = HttpClient(Android) {
install(SophonzKtorIntercept.Plugin)
}