Skip to content

Commit ed10620

Browse files
chore: update android build.gradle
- Remove unused 'org.jetbrains.kotlin.android' plugin - Remove 'kotlinOptions' block for JVM target compatibility update - Add exclusion for 'androidsupportmultidexversion.txt' in packagingOptions feat: add FlutterLogbackAppender for logging in Android - Add new FlutterLogbackAppender class for logging - Implement append method to handle log events - Include mainThreadHandler for posting log data asynchronously - Provide setChannel method for setting MethodChannel in FlutterLogbackAppender refactor: simplify channel set in OptimizelyFlutterSdkPlugin.java - Update channel set method to use static reference directly
1 parent 83a4cc3 commit ed10620

File tree

4 files changed

+43
-47
lines changed

4 files changed

+43
-47
lines changed

android/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
plugins {
22
id "com.android.library"
3-
id "org.jetbrains.kotlin.android"
43
}
54

65
group 'com.optimizely.optimizely_flutter_sdk'
@@ -54,10 +53,6 @@ android {
5453
sourceCompatibility JavaVersion.VERSION_1_8
5554
targetCompatibility JavaVersion.VERSION_1_8
5655
}
57-
58-
kotlinOptions {
59-
jvmTarget = "1.8"
60-
}
6156
packagingOptions {
6257
exclude 'androidsupportmultidexversion.txt'
6358
}
@@ -73,7 +68,6 @@ dependencies {
7368
implementation 'com.github.tony19:logback-android:3.0.0'
7469
implementation 'org.slf4j:slf4j-api:2.0.7'
7570

76-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.0"
7771
implementation "com.optimizely.ab:android-sdk:5.0.1"
7872
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
7973
implementation ('com.google.guava:guava:19.0') {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.optimizely.optimizely_flutter_sdk;
2+
3+
import android.os.Handler;
4+
import android.os.Looper;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
import ch.qos.logback.classic.spi.ILoggingEvent;
10+
import ch.qos.logback.core.AppenderBase;
11+
import io.flutter.plugin.common.MethodChannel;
12+
13+
public class FlutterLogbackAppender extends AppenderBase<ILoggingEvent> {
14+
15+
public static final String CHANNEL_NAME = "optimizely_flutter_sdk/logs";
16+
public static MethodChannel channel;
17+
private static final Handler mainThreadHandler = new Handler(Looper.getMainLooper());
18+
19+
public static void setChannel(MethodChannel channel) {
20+
FlutterLogbackAppender.channel = channel;
21+
}
22+
23+
@Override
24+
protected void append(ILoggingEvent event) {
25+
if (channel == null) {
26+
return;
27+
}
28+
29+
String message = event.getFormattedMessage();
30+
int level = event.getLevel().toInt();
31+
32+
Map<String, Object> logData = new HashMap<>();
33+
logData.put("level", level);
34+
logData.put("message", message);
35+
36+
mainThreadHandler.post(() -> {
37+
if (channel != null) {
38+
channel.invokeMethod("log", logData);
39+
}
40+
});
41+
}
42+
}

android/src/main/java/com/optimizely/optimizely_flutter_sdk/FlutterLogbackAppender.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

android/src/main/java/com/optimizely/optimizely_flutter_sdk/OptimizelyFlutterSdkPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
191191
}
192192

193193
// Clean up the channel
194-
FlutterLogbackAppender.Companion.setChannel(null);
194+
FlutterLogbackAppender.setChannel(null);
195195
}
196196

197197
@Override

0 commit comments

Comments
 (0)