Skip to content

Conversation

AbhijeetRanjan308
Copy link
Contributor

@AbhijeetRanjan308 AbhijeetRanjan308 commented Sep 22, 2025

Summary by CodeRabbit

  • New Features

    • Added a public plugin initialization API allowing apps to initialize the SDK with an app ID.
  • Chores

    • Android SDK settings now follow a dynamic compile/target SDK from project properties for better platform alignment.
    • Minimum Android version remains unchanged.
    • Simplified lint configuration to reduce build noise and warnings.

Copy link

coderabbitai bot commented Sep 22, 2025

Walkthrough

Updated Android Gradle config to use a dynamic sdk value (from rootProject.findProperty('compileSdkVersion') or default 34), set compileSdkVersion and targetSdkVersion to that sdk, kept minSdkVersion at 16, and simplified lintOptions. Added a new init method pathway: the Flutter API exposes KommunicateFlutterPlugin.init(String appId) which calls the native method channel; Android handler (KmMethodHandler.onMethodCall) receives "init" and invokes Kommunicate.init(context, initAppID) with error propagation.

Changes

Cohort / File(s) Summary of edits
Android build config
android/build.gradle
Replaced static compileSdkVersion 33 with dynamic sdk = rootProject.findProperty('compileSdkVersion')?.toInteger() ?: 34; set compileSdkVersion sdk and added targetSdkVersion sdk; retained minSdkVersion 16; simplified lintOptions to lintOptions { disable 'InvalidPackage' }.
Android plugin handler
android/src/main/java/.../KmMethodHandler.java
Added handling for "init" in onMethodCall: casts args to String initAppID, calls Kommunicate.init(context, initAppID) within try-catch, and uses result.error on exception. Positioned after getPlatformVersion branch.
Dart API surface
lib/kommunicate_flutter.dart
Added public static method init(String appId) that invokes native "init" via existing method channel, exposing plugin initialization from Dart.

Sequence Diagram(s)

sequenceDiagram
  participant Flutter as Flutter App
  participant Dart as KommunicateFlutterPlugin
  participant Channel as MethodChannel
  participant Android as KmMethodHandler
  participant SDK as Kommunicate SDK

  note over Dart,Channel: User calls KommunicateFlutterPlugin.init(appId)
  Dart->>Channel: invokeMethod("init", appId)
  Channel->>Android: onMethodCall("init", appId)
  Android->>SDK: Kommunicate.init(context, appId)
  SDK-->>Android: success / throws
  alt success
    Android-->>Channel: result.success(null)
  else error
    Android-->>Channel: result.error(code, message, details)
  end
  Channel-->>Dart: future completes
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • prateek-kommunicate
  • adarshmishra

Poem

"A rabbit tapped the channel wide,
Sent an appId for a ride.
Gradle flexed its SDK seam,
Init sprang up — a tiny dream.
Hooray, our chats hop, swift and spry!" 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary change: making compileSdkVersion configurable per the client project with a default of 34. The android/build.gradle changes in the summary show compileSdkVersion replaced by a dynamic value derived from rootProject.findProperty(...) with a fallback to 34 (and targetSdkVersion added), so the title matches the main intent of the changeset and is clear for reviewers. It is specific, on-topic, and avoids unnecessary noise.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch updated-compile-sdk-version

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
android/build.gradle (2)

32-32: Target SDK in a library module is typically ignored; consider removing or decoupling.

Setting targetSdkVersion in an Android library rarely affects the published AAR and can mislead consumers (it may only impact test APKs). Consider removing it or leaving it fixed/documented.

Possible change:

-        targetSdkVersion sdk
+        // targetSdkVersion is generally ignored for libraries; omit to avoid confusion.
+        // If you keep it, consider a fixed value or a separate override property.

35-35: Use the modern lint DSL; lintOptions is deprecated.

AGP 7.x supports the lint {} block and AGP 8 removes lintOptions. Migrate now for forward compatibility.

Apply this diff:

-    lintOptions { disable 'InvalidPackage' }
+    lint {
+        disable += ['InvalidPackage']
+    }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3f7393 and cb04d37.

📒 Files selected for processing (1)
  • android/build.gradle (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/kommunicate_flutter.dart (1)

16-18: Tighten API: return Future and validate appId before invoking native.

Small clarity/UX win and avoids a roundtrip with empty input.

-  static Future<dynamic> init(String appId) async {
-    return await _channel.invokeMethod('init', appId);
-  }
+  static Future<void> init(String appId) async {
+    if (appId.isEmpty) {
+      throw ArgumentError.value(appId, 'appId', 'must not be empty');
+    }
+    await _channel.invokeMethod<void>('init', appId);
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 833faa2 and 71559df.

📒 Files selected for processing (2)
  • android/src/main/java/io/kommunicate/kommunicate_flutter_plugin/KmMethodHandler.java (1 hunks)
  • lib/kommunicate_flutter.dart (1 hunks)

Comment on lines +69 to +75
} else if (call.method.equals("init")) {
try {
final String initAppID = (String) call.arguments();
Kommunicate.init(context, initAppID);
} catch (Exception e) {
result.error(ERROR, e.getMessage(), null);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Complete the MethodChannel result and validate input for "init".

The branch doesn’t call result.success(...), which can leave the Dart Future pending. Also, guard against empty appId and prefer e.toString() to avoid null messages.

 } else if (call.method.equals("init")) {
-    try {
-        final String initAppID = (String) call.arguments();
-        Kommunicate.init(context, initAppID);
-    } catch (Exception e) {
-        result.error(ERROR, e.getMessage(), null);
-    }
+    try {
+        final String initAppID = (String) call.arguments();
+        if (TextUtils.isEmpty(initAppID)) {
+            result.error(ERROR, "appId is missing", null);
+            return;
+        }
+        Kommunicate.init(context, initAppID);
+        result.success(null); // complete Future<void>
+    } catch (Exception e) {
+        result.error(ERROR, e.toString(), null);
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (call.method.equals("init")) {
try {
final String initAppID = (String) call.arguments();
Kommunicate.init(context, initAppID);
} catch (Exception e) {
result.error(ERROR, e.getMessage(), null);
}
} else if (call.method.equals("init")) {
try {
final String initAppID = (String) call.arguments();
if (TextUtils.isEmpty(initAppID)) {
result.error(ERROR, "appId is missing", null);
return;
}
Kommunicate.init(context, initAppID);
result.success(null); // complete Future<void>
} catch (Exception e) {
result.error(ERROR, e.toString(), null);
}
🤖 Prompt for AI Agents
In
android/src/main/java/io/kommunicate/kommunicate_flutter_plugin/KmMethodHandler.java
around lines 69 to 75, the "init" branch neither returns a success to the
MethodChannel nor validates the input and uses e.getMessage() which can be null;
update the handler to validate that the received appId is a non-empty string and
if invalid call result.error with a clear code/message, wrap Kommunicate.init in
try/catch and on success call result.success(null) (or a confirmation value),
and in the catch use result.error(ERROR, e.toString(), null) to ensure the Dart
Future completes and the full exception text is logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant