microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
296 stars 199 forks source link

usage on Android #3929

Open geoffrey-vl opened 6 days ago

geoffrey-vl commented 6 days ago

How can this be used in Android applications now that ApplicationInsights-Android has been deprecated? Specifically configuring the connection string is a bit non-Android. On Android you don't typically set environment variables, or put Json config files next to your appinsights jar file as there are no jar files in the end.

geoffrey-vl commented 5 days ago

For now I have something in line of this:

build.gradle:

dependencies {
    ....
    implementation "com.microsoft.azure:applicationinsights-core:3.6.1"
    implementation "com.microsoft.azure:applicationinsights-runtime-attach:3.6.1"
    ....
}

Java:

private static final String SYSPROP_CONN_STRING = "applicationinsights.connection.string";

// setup
System.setProperty(SYSPROP_CONN_STRING, connString);
com.microsoft.applicationinsights.attach.ApplicationInsights.attach();

// use
TelemetryClient client = new TelemetryClient();
client.trackEvent("somedata");
client.flush();

It fails however due to missing Java Optional class (java.lang.NoClassDefFoundError: Failed resolution of: Ljava/util/Optional;). Our target platform is still running Android 5.